Spring 数据 Neo4j 4.2.0.BUILD-SNAPSHOT OGM 2.1.0-SNAPSHOT NullPointerException
Spring Data Neo4j 4.2.0.BUILD-SNAPSHOT OGM 2.1.0-SNAPSHOT NullPointerException
在最近的 Spring Data Neo4j 4.2.0.BUILD-SNAPSHOT
和 OGM 2.1.0-SNAPSHOT
中,我的测试因以下 NPE 而失败(几天前一切正常,我的代码没有一行未更改):
java.lang.NullPointerException
at org.neo4j.ogm.entity.io.EntityAccessManager.getRelationalReaders(EntityAccessManager.java:355)
at org.neo4j.ogm.context.EntityGraphMapper.bothWayMappingRequired(EntityGraphMapper.java:893)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:396)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:230)
at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:134)
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:419)
at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:133)
at com.sun.proxy.$Proxy115.save(Unknown Source)
at org.springframework.data.neo4j.repository.support.SimpleGraphRepository.save(SimpleGraphRepository.java:70)
at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
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.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
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.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy128.save(Unknown Source)
at com.decisionwanted.domain.dao.decision.CharacteristicOptionDaoImpl.createOrUpdate(CharacteristicOptionDaoImpl.java:44)
at com.decisionwanted.domain.dao.decision.CharacteristicOptionDaoImpl.create(CharacteristicOptionDaoImpl.java:24)
at com.decisionwanted.domain.DecisionCharacteristicTest.testDecisionCharacteristicOptions(DecisionCharacteristicTest.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod.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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.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)
我的代码:
@NodeEntity
public class Characteristic extends Authorable {
public final static String NODE_NAME = "Characteristic";
private final static String CONTAINS = "CONTAINS";
private final static String DEFINED_BY = "DEFINED_BY";
private String name;
private String description;
private Type type;
private Mode mode;
private boolean sortable;
@Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
private Set<CharacteristicOption> options = new HashSet<>();
@Relationship(type = CONTAINS, direction = Relationship.INCOMING)
private CharacteristicGroup group;
@Relationship(type = DEFINED_BY, direction = Relationship.OUTGOING)
private Decision owner;
public Characteristic() {
}
public Characteristic(String name, String description, Type type, Mode mode, Decision owner, User author) {
this.name = name;
this.description = description;
this.type = type;
this.mode = mode;
this.owner = owner;
setAuthor(author);
}
public Characteristic(String name, String description, Type type, Mode mode, Decision owner, User author, CharacteristicGroup group) {
this(name, description, type, mode, owner, author);
this.group = group;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
this.mode = mode;
}
public boolean isSortable() {
return sortable;
}
public void setSortable(boolean sortable) {
this.sortable = sortable;
}
public Set<CharacteristicOption> getOptions() {
return options;
}
public void setOptions(Set<CharacteristicOption> options) {
this.options = options;
}
public boolean addOption(CharacteristicOption option) {
return options.add(option);
}
public CharacteristicGroup getGroup() {
return group;
}
public void setGroup(CharacteristicGroup group) {
this.group = group;
}
public Decision getOwner() {
return owner;
}
public void setOwner(Decision owner) {
this.owner = owner;
}
public static enum Type {
//@formatter:off
BOOLEAN("Boolean"),
INTEGER("Integer"),
STRING("String");
//@formatter:on
private final String name;
Type(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public static enum Mode {
//@formatter:off
CHECKBOX("CheckBox"),
SLIDER("Slider"),
SELECTBOX("SelectBox"),
RADIOGROUP("String");
//@formatter:on
private final String name;
Mode(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}
@NodeEntity
public class CharacteristicOption extends BaseEntity {
private final static String CONTAINS = "CONTAINS";
private String name;
private String description;
private Object value;
@Relationship(type = CONTAINS, direction = Relationship.INCOMING)
private Characteristic characteristic;
public CharacteristicOption() {
}
public CharacteristicOption(String name, String description, Object value, Characteristic characteristic) {
this.name = name;
this.description = description;
this.value = value;
this.characteristic = characteristic;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public Characteristic getCharacteristic() {
return characteristic;
}
public void setCharacteristic(Characteristic characteristic) {
this.characteristic = characteristic;
}
}
@Override
public CharacteristicOption createOrUpdate(CharacteristicOption characteristicOption) {
auditing(characteristicOption);
return characteristicOptionRepository.save(characteristicOption);
}
这个问题的原因是什么以及如何解决?
您的 CharacteristicOption
class 声明了一个字段:
private Object value;
最近对 2.1.0-SNAPSHOT 的提交排除了 Object
和 Object[]
引用作为持久属性。因此,OGM 试图通过关系映射 value
属性,而不是作为简单的节点属性。
这已在最新的快照版本中得到纠正。
在最近的 Spring Data Neo4j 4.2.0.BUILD-SNAPSHOT
和 OGM 2.1.0-SNAPSHOT
中,我的测试因以下 NPE 而失败(几天前一切正常,我的代码没有一行未更改):
java.lang.NullPointerException
at org.neo4j.ogm.entity.io.EntityAccessManager.getRelationalReaders(EntityAccessManager.java:355)
at org.neo4j.ogm.context.EntityGraphMapper.bothWayMappingRequired(EntityGraphMapper.java:893)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:396)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:230)
at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:134)
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:419)
at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:133)
at com.sun.proxy.$Proxy115.save(Unknown Source)
at org.springframework.data.neo4j.repository.support.SimpleGraphRepository.save(SimpleGraphRepository.java:70)
at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
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.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
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.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy128.save(Unknown Source)
at com.decisionwanted.domain.dao.decision.CharacteristicOptionDaoImpl.createOrUpdate(CharacteristicOptionDaoImpl.java:44)
at com.decisionwanted.domain.dao.decision.CharacteristicOptionDaoImpl.create(CharacteristicOptionDaoImpl.java:24)
at com.decisionwanted.domain.DecisionCharacteristicTest.testDecisionCharacteristicOptions(DecisionCharacteristicTest.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod.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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.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)
我的代码:
@NodeEntity
public class Characteristic extends Authorable {
public final static String NODE_NAME = "Characteristic";
private final static String CONTAINS = "CONTAINS";
private final static String DEFINED_BY = "DEFINED_BY";
private String name;
private String description;
private Type type;
private Mode mode;
private boolean sortable;
@Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
private Set<CharacteristicOption> options = new HashSet<>();
@Relationship(type = CONTAINS, direction = Relationship.INCOMING)
private CharacteristicGroup group;
@Relationship(type = DEFINED_BY, direction = Relationship.OUTGOING)
private Decision owner;
public Characteristic() {
}
public Characteristic(String name, String description, Type type, Mode mode, Decision owner, User author) {
this.name = name;
this.description = description;
this.type = type;
this.mode = mode;
this.owner = owner;
setAuthor(author);
}
public Characteristic(String name, String description, Type type, Mode mode, Decision owner, User author, CharacteristicGroup group) {
this(name, description, type, mode, owner, author);
this.group = group;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
this.mode = mode;
}
public boolean isSortable() {
return sortable;
}
public void setSortable(boolean sortable) {
this.sortable = sortable;
}
public Set<CharacteristicOption> getOptions() {
return options;
}
public void setOptions(Set<CharacteristicOption> options) {
this.options = options;
}
public boolean addOption(CharacteristicOption option) {
return options.add(option);
}
public CharacteristicGroup getGroup() {
return group;
}
public void setGroup(CharacteristicGroup group) {
this.group = group;
}
public Decision getOwner() {
return owner;
}
public void setOwner(Decision owner) {
this.owner = owner;
}
public static enum Type {
//@formatter:off
BOOLEAN("Boolean"),
INTEGER("Integer"),
STRING("String");
//@formatter:on
private final String name;
Type(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public static enum Mode {
//@formatter:off
CHECKBOX("CheckBox"),
SLIDER("Slider"),
SELECTBOX("SelectBox"),
RADIOGROUP("String");
//@formatter:on
private final String name;
Mode(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}
@NodeEntity
public class CharacteristicOption extends BaseEntity {
private final static String CONTAINS = "CONTAINS";
private String name;
private String description;
private Object value;
@Relationship(type = CONTAINS, direction = Relationship.INCOMING)
private Characteristic characteristic;
public CharacteristicOption() {
}
public CharacteristicOption(String name, String description, Object value, Characteristic characteristic) {
this.name = name;
this.description = description;
this.value = value;
this.characteristic = characteristic;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public Characteristic getCharacteristic() {
return characteristic;
}
public void setCharacteristic(Characteristic characteristic) {
this.characteristic = characteristic;
}
}
@Override
public CharacteristicOption createOrUpdate(CharacteristicOption characteristicOption) {
auditing(characteristicOption);
return characteristicOptionRepository.save(characteristicOption);
}
这个问题的原因是什么以及如何解决?
您的 CharacteristicOption
class 声明了一个字段:
private Object value;
最近对 2.1.0-SNAPSHOT 的提交排除了 Object
和 Object[]
引用作为持久属性。因此,OGM 试图通过关系映射 value
属性,而不是作为简单的节点属性。
这已在最新的快照版本中得到纠正。