I create enties and RelationshipEntity that point between them. I put RelationshipEntity elements inside an object and then save the object. It also automatically saves the RelationshipEntity function.
I know that the connection is saved, since I can get both objects and relationships. However, when I get the starting or ending entity, its set of relationships is empty.
I tried to make impatient prey, but not joy.
Can anyone see what I'm doing wrong here?
My essence ...
@NodeEntity public class Thing { public Thing() { super(); } @GraphId private Long nodeId; private Long uuid;
My RelationshipEntity ...
@RelationshipEntity public class ThingRelationship { public ThingRelationship() { super(); }
And finally, my test .... (final statement not executed)
@Test @Rollback(false) public void testAddRelationship(){ Thing thingA = new Thing(); template.save(thingA); Thing retrievedThingA = template.findOne(thingA.getNodeId(), Thing.class); //returns a thing OK assertNotNull(retrievedThingA); Thing thingB = new Thing(); template.save(thingB); Thing retrievedThingB = template.findOne(thingB.getNodeId(), Thing.class); //returns a thing OK assertNotNull(retrievedThingB); //Relationship ThingRelationship thingRelationship = thingB.relatedTo(thingA, "REALLY_REALLY_LIKES"); template.save(thingRelationship); ThingRelationship thingRelationshipRetrieved = template.findOne(thingRelationship.getNodeId(), ThingRelationship.class); assertEquals(thingB.getNodeId(), thingRelationshipRetrieved.getStartThing().getNodeId()); assertEquals(thingA.getNodeId(), thingRelationshipRetrieved.getEndThing().getNodeId()); Thing retrievedThingFinal = template.findOne(thingB.getNodeId(), Thing.class); template.fetch(retrievedThingFinal.relationships); assertEquals(1, retrievedThingFinal.getRelationships().size()); //FAILS HERE }
The final statement fails with "Expected 1, but 0 found" :( Should the returned person not be in the Escort state, as I was looking forward to?
source share