我正在spring-boot 1.5.1
使用spring-boot-starter-data-neo4j
我的neo4j配置看起来像:
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration
// @ComponentScan
@EnableNeo4jRepositories(basePackages = "org.nymeria.umapi.spring.neo4j")
@EnableTransactionManagement
public class Application {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Application.class, args);
}
}
在一个名为org.nymeria.umapi.spring.neo4j.movies
的软件包里面,我有一个电影模型/存储库/控制器软件包,它的工作正常。
我创建了名为org.nymeria.umapi.spring.neo4j.tvshow
的anoter包,里面有repository / models包,保存数据不起作用。
我的TvShow模型类看起来像:
@NodeEntity
public class TvShow {
@GraphId
private Long tvshow_id;
@Property
EnumClass genre;
@Index(unique = true)
@Property(name = "imdb_ud")
String imdbID;
@Property
List<SimplePojo> property = new ArrayList<>();
public TvShow () {
super();
}
// getter and setter ...
}
然后我就是简单的界面TvShowRepository
,当我这么做的时候
tvshowRepo.save(tvshow);
抛出NPE异常
java.lang.NullPointerException
at org.neo4j.ogm.compiler.builders.node.DefaultNodeBuilder.addProperty(DefaultNodeBuilder.java:45)
at org.neo4j.ogm.context.EntityGraphMapper.updateNode(EntityGraphMapper.java:249)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:220)
at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:135)
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:83)
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:44)
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:447)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:131)
at com.sun.proxy.$Proxy80.save(Unknown Source)
at org.springframework.data.neo4j.repository.support.SimpleNeo4jRepository.save(SimpleNeo4jRepository.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:504)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:489)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy97.save(Unknown Source)
at org.nymeria.umapi.spring.movie.feeder.utils.TvShowFactory.createTvShow(TvShowFactory.java:56)
at org.nymeria.umapi.spring.movie.feeder.utils.TvShowFactoryService.getOrCreateTvShow(TvShowFactoryService.java:17)
at org.nymeria.umapi.spring.movie.feeder.utils.TvShowFactoryServiceTest.storeInDatabase(TvShowFactoryServiceTest.java:60)
at org.nymeria.umapi.spring.movie.feeder.utils.TvShowFactoryServiceTest.test(TvShowFactoryServiceTest.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
我不知道它是配置错误还是我做错了什么或是错误
答案 0 :(得分:2)
问题很可能是
@Property
List<SimplePojo> property = new ArrayList<>();
节点不能将嵌套对象作为属性。
(即使如此,NullPointerException没有帮助 - 请在https://github.com/neo4j/neo4j-ogm/issues打开一个问题以引发更有用的错误)