在我的Spring Data Neo4j应用程序中,我实现了创建节点和关系的测试。到目前为止一切正常。
为了提高应用程序性能,我想尝试使用关系属性的手动索引。
我添加了以下Neo4j APOC触发器,必须在manuall index中添加和删除关系属性:
CALL apoc.trigger.add('HAS_VALUE_ON_ADD_TO_INDEX', 'UNWIND {createdRelationships} AS r MATCH (d:Decision)-[r:HAS_VALUE_ON]->(ch:Characteristic)
CALL apoc.index.addRelationship(r, keys(r)) RETURN count(*)', {phase:'after'});
CALL apoc.trigger.add('HAS_VALUE_ON_REMOVE_FROM_INDEX', "UNWIND {deletedRelationships} AS r MATCH (d:Decision)-[r:HAS_VALUE_ON]->(ch:Characteristic)
CALL apoc.index.removeRelationshipByName('HAS_VALUE_ON', r) RETURN count(*)", {phase:'after'});
一旦我添加了这些索引,我的测试(如上所述)就会失败,并出现以下异常:
org.springframework.dao.InvalidDataAccessApiUsageException: Error executing triggers {HAS_VALUE_ON_REMOVE_FROM_INDEX=Unable to load NODE with id 3.}; nested exception is org.neo4j.ogm.exception.TransactionException: Error executing triggers {HAS_VALUE_ON_REMOVE_FROM_INDEX=Unable to load NODE with id 3.}
at org.springframework.data.neo4j.transaction.SessionFactoryUtils.convertOgmAccessException(SessionFactoryUtils.java:144)
at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.doCommit(Neo4jTransactionManager.java:324)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:746)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:532)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:304)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at com.decisionwanted.domain.service.data.DataGeneratorImpl$$EnhancerBySpringCGLIB$$fe2b32e9.cleanDb(<generated>)
at com.decisionwanted.domain.DecisionCharacteristicIT.setUp(DecisionCharacteristicIT.java:180)
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.RunBefores.evaluate(RunBefores.java:24)
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:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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:190)
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)
Caused by: org.neo4j.ogm.exception.TransactionException: Error executing triggers {HAS_VALUE_ON_REMOVE_FROM_INDEX=Unable to load NODE with id 3.}
at org.neo4j.ogm.drivers.bolt.transaction.BoltTransaction.commit(BoltTransaction.java:87)
at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.doCommit(Neo4jTransactionManager.java:307)
... 38 more
Caused by: org.neo4j.driver.v1.exceptions.DatabaseException: Error executing triggers {HAS_VALUE_ON_REMOVE_FROM_INDEX=Unable to load NODE with id 3.}
at org.neo4j.driver.internal.net.SocketResponseHandler.handleFailureMessage(SocketResponseHandler.java:83)
at org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.unpackFailureMessage(PackStreamMessageFormatV1.java:470)
at org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.read(PackStreamMessageFormatV1.java:431)
at org.neo4j.driver.internal.net.SocketClient.receiveOne(SocketClient.java:196)
at org.neo4j.driver.internal.net.SocketClient.receiveAll(SocketClient.java:190)
at org.neo4j.driver.internal.net.SocketConnection.receiveAll(SocketConnection.java:203)
at org.neo4j.driver.internal.net.SocketConnection.sync(SocketConnection.java:157)
at org.neo4j.driver.internal.net.ConcurrencyGuardingConnection.sync(ConcurrencyGuardingConnection.java:137)
at org.neo4j.driver.internal.net.pooling.PooledSocketConnection.sync(PooledSocketConnection.java:157)
at org.neo4j.driver.internal.ExplicitTransaction.close(ExplicitTransaction.java:115)
at org.neo4j.ogm.drivers.bolt.transaction.BoltTransaction.commit(BoltTransaction.java:73)
... 39 more
我做错了什么以及如何解决?
已更新
我使用Spring Boot测试:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestApplication.class })
public class DecisionCharacteristicIT {
@Test
public void testRelationshipValueTriggerAndIndex() {
// test logic
}
}