触发 Cypher 查询以了解 no.of 关系
Firing Cypher query to know no.of relations
public int getNoOfRelations(long entityId, String relationShipName) {
int noOfRelations = 0;
Map<String, Object> map = new SeqncMap<String, Object>();
map.put("objectId", entityId);
String query = "MATCH (object1)-[r:" + relationShipName
+ "]->(object2) WHERE id(object2) in {objectId} return count(r)";
Result result = session.query(query, map);
Iterator<Map<String, Object>> iterator = result.iterator();
if (iterator != null && iterator.hasNext()) {
Map<String, Object> next = iterator.next();
noOfRelations = (int) next.get("count");
}
return noOfRelations;
}
在 "session.query(query, map);"
期间出现以下异常
org.neo4j.ogm.exception.TransactionException: Failed to execute request:
17:38:35,793 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.neo4j.ogm.drivers.http.transaction.HttpTransaction.rollback(HttpTransaction.java:49)
17:38:35,796 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.rollback(Neo4jTransactionManager.java:60)
17:38:35,800 ERROR [stderr] (seqnc-executor-connector-threads - 1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:38:35,803 ERROR [stderr] (seqnc-executor-connector-threads - 1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
17:38:35,805 ERROR [stderr] (seqnc-executor-connector-threads - 1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17:38:35,809 ERROR [stderr] (seqnc-executor-connector-threads - 1) at java.lang.reflect.Method.invoke(Method.java:606)
17:38:35,813 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
17:38:35,817 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
17:38:35,821 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
17:38:35,827 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
17:38:35,831 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
17:38:35,840 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
17:38:35,843 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
17:38:35,847 ERROR [stderr] (seqnc-executor-connector-threads - 1) at com.sun.proxy.$Proxy55.rollback(Unknown Source)
17:38:35,848 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:539)
17:38:35,854 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:285)
17:38:35,864 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
17:38:35,868 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
17:38:35,875 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
17:38:35,880 ERROR [stderr] (seqnc-executor-connector-threads - 1) at com.seqnc.ui.service.impl.CompanyServiceImpl$$EnhancerBySpringCGLIB$$e90d4dcf.deleteLocation(<generated>)
17:38:35,884 ERROR [stderr] (seqnc-executor-connector-threads - 1) at com.seqnc.ui.executors.company.department.DeleteLocationExecutor.execute(DeleteLocationExecutor.java:
38)
您的查询在 WHERE
子句中有一个 IN
谓词:
WHERE id(object2) in {objectId}
这意味着 objectId
应该是一个集合。
但是,它被设置为单个 long
:map.put("objectId", entityId)
之前声明了 long entityId
。
public int getNoOfRelations(long entityId, String relationShipName) {
int noOfRelations = 0;
Map<String, Object> map = new SeqncMap<String, Object>();
map.put("objectId", entityId);
String query = "MATCH (object1)-[r:" + relationShipName
+ "]->(object2) WHERE id(object2) in {objectId} return count(r)";
Result result = session.query(query, map);
Iterator<Map<String, Object>> iterator = result.iterator();
if (iterator != null && iterator.hasNext()) {
Map<String, Object> next = iterator.next();
noOfRelations = (int) next.get("count");
}
return noOfRelations;
}
在 "session.query(query, map);"
期间出现以下异常 org.neo4j.ogm.exception.TransactionException: Failed to execute request:
17:38:35,793 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.neo4j.ogm.drivers.http.transaction.HttpTransaction.rollback(HttpTransaction.java:49)
17:38:35,796 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.rollback(Neo4jTransactionManager.java:60)
17:38:35,800 ERROR [stderr] (seqnc-executor-connector-threads - 1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:38:35,803 ERROR [stderr] (seqnc-executor-connector-threads - 1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
17:38:35,805 ERROR [stderr] (seqnc-executor-connector-threads - 1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17:38:35,809 ERROR [stderr] (seqnc-executor-connector-threads - 1) at java.lang.reflect.Method.invoke(Method.java:606)
17:38:35,813 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
17:38:35,817 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
17:38:35,821 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
17:38:35,827 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
17:38:35,831 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
17:38:35,840 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
17:38:35,843 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
17:38:35,847 ERROR [stderr] (seqnc-executor-connector-threads - 1) at com.sun.proxy.$Proxy55.rollback(Unknown Source)
17:38:35,848 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:539)
17:38:35,854 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:285)
17:38:35,864 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
17:38:35,868 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
17:38:35,875 ERROR [stderr] (seqnc-executor-connector-threads - 1) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
17:38:35,880 ERROR [stderr] (seqnc-executor-connector-threads - 1) at com.seqnc.ui.service.impl.CompanyServiceImpl$$EnhancerBySpringCGLIB$$e90d4dcf.deleteLocation(<generated>)
17:38:35,884 ERROR [stderr] (seqnc-executor-connector-threads - 1) at com.seqnc.ui.executors.company.department.DeleteLocationExecutor.execute(DeleteLocationExecutor.java:
38)
您的查询在 WHERE
子句中有一个 IN
谓词:
WHERE id(object2) in {objectId}
这意味着 objectId
应该是一个集合。
但是,它被设置为单个 long
:map.put("objectId", entityId)
之前声明了 long entityId
。