2016-07-13 11 views
0
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; 
} 

Gibt folgende Ausnahme während "session.query (query, map);"Firing Cypher Abfrage, um die Anzahl der Beziehungen zu kennen

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)

+0

Bitte buchen Sie die Stack-Ablaufverfolgung von session.query(). Welche Version von SDN und OGM verwenden Sie? – Luanne

Antwort

0

Ihre Suche hat ein IN Prädikat in der WHERE Klausel:

WHERE id(object2) in {objectId} 

die objectId impliziert soll eine Sammlung sein.

Es ist jedoch als eine einzige long: map.put("objectId", entityId) mit einer früheren Deklaration von long entityId festgelegt.

+0

Danke. Du hast recht. Problem gelöst. Hinzufügen eines weiteren Punktes, den ich bemerkt habe, Wenn der Typ von "entityId" in Wrapper Long geändert wird, wird dieser Code funktionieren. wenn es primitiv lang ist, sollte es WHERE ID sein (object2) = entityId – madireddy

+0

Wenn es Ihr Problem gelöst hat, sollten Sie in Betracht ziehen, die Antwort dann zu akzeptieren. Nicht nur für mich, sondern für andere Menschen als das gleiche Problem zu finden und eine unakzeptierte Antwort zu finden und nicht auf Ihren Kommentar zu schauen. –

Verwandte Themen