Spring Neo4j data not populating RelationshipEntity

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; // unique across domains @Fetch @RelatedToVia(type="some default type", direction = Direction.BOTH) Set<ThingRelationship> relationships = new HashSet<ThingRelationship>(); @Fetch private Set<Property<?>> properties; public ThingRelationship relatedTo(Thing thing, String relationshipType){ ThingRelationship thingRelationship = new ThingRelationship(this, thing, relationshipType); relationships.add(thingRelationship); return thingRelationship; } public Set<ThingRelationship> getRelationships() { return relationships; } ... } 

My RelationshipEntity ...

 @RelationshipEntity public class ThingRelationship { public ThingRelationship() { super(); } //incremental neo4j set ID @GraphId Long nodeId; //Start and end nodes @StartNode Thing startThing; @EndNode Thing endThing; //Relationship Type @org.springframework.data.neo4j.annotation.RelationshipType String relationship; public ThingRelationship(Thing startThing, Thing endThing, String relationship) { super(); this.startThing = startThing; this.endThing = endThing; this.relationship = relationship; } 

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?

+4
source share
1 answer

The problem is with the line below

 @RelatedToVia(type="some default type", direction = Direction.BOTH) Set<ThingRelationship> relationships = new HashSet<ThingRelationship>(); 

A change is made to this below.

 @RelatedToVia(type="REALLY_REALLY_LIKES", direction = Direction.BOTH) Set<ThingRelationship> relationships = new HashSet<ThingRelationship>(); 

Not sure why it is not working if you are using a dynamic relationship.

+2
source

Source: https://habr.com/ru/post/1499489/


All Articles