Announcement Announcement Module
Collapse
No announcement yet.
Not able to fetch relationships of node using Spring Data Neo4J Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not able to fetch relationships of node using Spring Data Neo4J

    Uploaded my test code on https://github.com/jonam/SpringDataGraphSample

    If I uncomment line 85 in GraphEngineTest.java, it breaks, as the relationships are not being sent in the format that I can expect. I am currently using <spring-data-neo4j.version>2.1.0.RC2</spring-data-neo4j.version>. But this did not work with 2.0.1.RELEASE either. Also tried tweaking around with versions of other packages like spring, and neo4j but did not help.

    The error I see is below:

    -------------------------------------------------------------------------------
    Test set: com.graph.bio.GraphEngineTest
    -------------------------------------------------------------------------------
    Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 12.256 sec <<< FAILURE!
    proteinRelationship(com.graph.bio.GraphEngineTest) Time elapsed: 0.585 sec <<< ERROR!
    java.lang.ClassCastException: org.springframework.data.neo4j.fieldaccess.GraphBa ckedEntityIterableWrapper cannot be cast to com.graph.bio.domain.ProteinInteraction
    at com.graph.bio.GraphEngineTest.proteinRelationship( GraphEngineTest.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements .RunBeforeTestMethodCallbacks.evaluate(RunBeforeTe stMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements .RunAfterTestMethodCallbacks.evaluate(RunAfterTest MethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements .SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:222)
    at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:300)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:174 )
    at org.apache.maven.surefire.junit4.JUnit4TestSet.exe cute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.ex ecuteTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.in voke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.inv okeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$P roviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.i nvokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.r unSuitesInProcessWhenForked(SurefireStarter.java:1 07)
    at org.apache.maven.surefire.booter.ForkedBooter.main (ForkedBooter.java:68)

  • #2
    jonam_biz,

    In your code you have

    Code:
    @RelatedToVia(type = "INTERACTS_WITH", direction=Direction.BOTH)
    Collection<ProteinInteraction> proteinInteractions;
    
    
    
    protein1.interactsWith(protein2, "phosphorylation");
    protein2.interactsWith(protein1, "phosphorylation");
    template.save(protein1);
    template.save(protein2);
    Now, because the annotation says Direction.BOTH, only one relationship is created. Is that desirable? Secondly, if it is, you can drop the reverse call of
    Code:
    template.save(protein2)
    .

    Also, for testing, you can use
    Code:
    <bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase"/>
    to ensure your tests are fast and isolated.

    Does that help?

    Lasse

    Comment


    • #3
      Originally posted by lassewesth View Post
      jonam_biz,

      In your code you have

      Code:
      @RelatedToVia(type = "INTERACTS_WITH", direction=Direction.BOTH)
      Collection<ProteinInteraction> proteinInteractions;
      
      
      
      protein1.interactsWith(protein2, "phosphorylation");
      protein2.interactsWith(protein1, "phosphorylation");
      template.save(protein1);
      template.save(protein2);
      Now, because the annotation says Direction.BOTH, only one relationship is created. Is that desirable? Secondly, if it is, you can drop the reverse call of
      Code:
      template.save(protein2)
      .

      Also, for testing, you can use
      Code:
      <bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase"/>
      to ensure your tests are fast and isolated.

      Does that help?

      Lasse
      Originally posted by lassewesth View Post
      jonam_biz,

      In your code you have

      Code:
      @RelatedToVia(type = "INTERACTS_WITH", direction=Direction.BOTH)
      Collection<ProteinInteraction> proteinInteractions;
      
      
      
      protein1.interactsWith(protein2, "phosphorylation");
      protein2.interactsWith(protein1, "phosphorylation");
      template.save(protein1);
      template.save(protein2);
      Now, because the annotation says Direction.BOTH, only one relationship is created. Is that desirable? Secondly, if it is, you can drop the reverse call of
      Code:
      template.save(protein2)
      .



      Also, for testing, you can use
      Code:
      <bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase"/>
      to ensure your tests are fast and isolated.

      Does that help?

      Lasse
      I dropped that call, and I got and endNode null error.

      java.lang.IllegalArgumentException: Null parameter, startNode=NodeImpl#3, endNode=null, type=DynamicRelationshipType[INTERACTS_WITH] at org.neo4j.kernel.impl.core.NodeManager.createRelat ionship(NodeManager.java:290) at org.neo4j.kernel.impl.core.NodeImpl.createRelation shipTo(NodeImpl.jav
      a:499)
      at org.neo4j.kernel.impl.core.NodeProxy.createRelatio nshipTo(NodeProxy.java:198)
      at org.springframework.data.neo4j.support.mapping.Ent ityStateHandler.createRelationship(EntityStateHand ler.java:131)


      So I think you mean
      Code:
      protein2.interactsWith(protein1)
      ?
      I tried commenting that too:

      https://github.com/jonam/SpringDataG...ngineTest.java

      and I still get the original error that I got:

      java.lang.ClassCastException: org.springframework.data.neo4j.fieldaccess.GraphBa ckedEntityIterableWrapper cannot be cast to com.graph.bio.domain.ProteinInteraction
      at com.graph.bio.GraphEngineTest.proteinRelationship( GraphEngineTest.java:85)

      <bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase"/>

      I made that change to use ImpermanentGraphDatabase. Committed all my changes. Still getting same errors as I said above.

      Comment


      • #4
        Manoj,

        Try using
        Code:
        @RelatedToVia(type = "INTERACTS_WITH", direction = BOTH)
        Set<ProteinInteraction> proteinInteractions = new HashSet<ProteinInteraction>(  );
        - that makes the test pass.

        As to an explanation, I don't have a good one, what you are doing ought to work...

        Lasse

        Comment


        • #5
          Originally posted by lassewesth View Post
          Manoj,

          Try using
          Code:
          @RelatedToVia(type = "INTERACTS_WITH", direction = BOTH)
          Set<ProteinInteraction> proteinInteractions = new HashSet<ProteinInteraction>(  );
          - that makes the test pass.

          As to an explanation, I don't have a good one, what you are doing ought to work...

          Lasse
          Fantastic! That worked. Thanks for your help. I have committed my fixes so others can use them on github if needed. Yeah, let me know if there was a way to skip the initialization in future. I would have expected that not requiring initialization. I also saw it was not done in the spring-data examples, but I could be wrong.

          Comment


          • #6
            Manoj,

            I can't explain why initializing the Set made a difference - you are quite right that shouldn't be necessary.

            We did _just_ fix an issue with RelatedToVia mapping, so if you have spare time you could retest with the very latest SDN version...

            Anyway, workaround in place, good luck!

            Lasse

            Comment


            • #7
              Originally posted by lassewesth View Post
              Manoj,

              I can't explain why initializing the Set made a difference - you are quite right that shouldn't be necessary.

              We did _just_ fix an issue with RelatedToVia mapping, so if you have spare time you could retest with the very latest SDN version...

              Anyway, workaround in place, good luck!

              Lasse
              I am already using spring-data-neo4j-2.1.0.RC2. Is there a newer release? I cannot find a newer one here:

              http://repo.springsource.org/webapp/...ing-data-neo4j

              Comment


              • #8
                There are snapshots, and RC3 is due out tomorrow-ish.

                Lasse

                Comment

                Working...
                X