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;
}

Giving following exception during "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)

Luanne
  • 19,145
  • 1
  • 39
  • 51
madireddy
  • 107
  • 3
  • 13
  • Please post the stack trace originating from session.query(). Which version of SDN and OGM are you using? – Luanne Jul 13 '16 at 12:31

1 Answers1

0

Your query has an IN predicate in the WHERE clause:

WHERE id(object2) in {objectId}

which implies objectId should be a collection.

However, it's set as a single long: map.put("objectId", entityId) with a previous declaration of long entityId.

Frank Pavageau
  • 11,477
  • 1
  • 43
  • 53
  • Thanks. You are right. Solved the problem. Adding one more point which i noticed, If type of "entityId" is changed to wrapper Long, this code will work. if it's primitive long, it should be WHERE id(object2)=entityId – madireddy Jul 14 '16 at 13:40
  • If it solved your problem, you should consider accepting the answer then. Not only for me, but for other people than encounter the same problem and find an unaccepted answer and don't look at your comment. – Frank Pavageau Jul 15 '16 at 20:18