cassandra datastax 编写生成的代码时出现意外错误:java.lang.NullPointerException
Posted
技术标签:
【中文标题】cassandra datastax 编写生成的代码时出现意外错误:java.lang.NullPointerException【英文标题】:cassandra datastax Unexpected error while writing generated code: java.lang.NullPointerException 【发布时间】:2020-11-08 04:36:19 【问题描述】:我有一个java类
import com.datastax.oss.driver.api.mapper.annotations.Dao;
import com.datastax.oss.driver.api.mapper.annotations.Delete;
import com.datastax.oss.driver.api.mapper.annotations.Insert;
import com.datastax.oss.driver.api.mapper.annotations.Select;
@Dao
public interface ProductDao
@Select
Product findById(UUID productId);
@Insert
void save(Product product);
@Delete
void delete(Product product);
我想用它来获取 cassandra 记录。 我正在尝试文档 - https://github.com/datastax/java-driver/tree/4.x/manual/mapper 当我尝试用 maven 构建它时,我得到了一个 NPE
ProductDao.java:[10,8] Unexpected error while writing generated code: java.lang.NullPointerException
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.util.HierarchyScanner.traverseHierarchy(HierarchyScanner.java:169)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.util.HierarchyScanner.resolveHierarchyScanStrategy(HierarchyScanner.java:97)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.util.HierarchyScanner.resolveTypeHierarchy(HierarchyScanner.java:81)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.entity.DefaultEntityFactory.getDefinition(DefaultEntityFactory.java:80)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.dao.DaoSelectMethodGenerator.generate(DaoSelectMethodGenerator.java:98)
[ERROR] at java.util.Optional.flatMap(Optional.java:241)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.dao.DaoImplementationGenerator.getContents(DaoImplementationGenerator.java:331)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.SingleFileCodeGenerator.generate(SingleFileCodeGenerator.java:43)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.MapperProcessor.processAnnotatedTypes(MapperProcessor.java:125)
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.MapperProcessor.process(MapperProcessor.java:90)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:802)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:713)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1043)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1184)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:523)
[ERROR] at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
[ERROR] at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
[ERROR] at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
[ERROR] at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:943)
[ERROR] at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:137)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
无法从根本上导致错误,感谢任何帮助。
【问题讨论】:
驱动版本是多少?另外,请将您的 pom.xml 与配置的相关部分放在一起 【参考方案1】:堆栈跟踪中的这一行以及从 - 开始向上的行
[ERROR] at com.datastax.oss.driver.internal.mapper.processor.entity.DefaultEntityFactory.getDefinition(DefaultEntityFactory.java:80)
向我表明这是实体类的问题,而不是道本身。考虑到这一点,我可以通过删除 Dao 要返回的类上的 @Entity 注释来复制此堆栈跟踪,在您的情况下,这将是 Product。
我的期望是 Product 类没有正确注释,我们需要从该类中添加代码来进一步诊断/确认。
【讨论】:
以上是关于cassandra datastax 编写生成的代码时出现意外错误:java.lang.NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章
Datastax C# 驱动程序中的 Cassandra timeuuid
使用 datastax java 驱动程序 2.1.4 连接到 Cassandra 集群的速度太慢
com.datastax.oss -> java-driver-core 和 com.datastax.cassandra -> cassandra-driver-core 之间的 Cas
构建 Apache Cassandra 的 DataStax 发行版