java - Spring Data Neo4j not populating RelationshipEntity -
i creating enties , relationshipentitys point between them. place relationshipentitys within entity , save entity. saves relationshipentity automatically.
i know relationship has saved can retrieve both entities , relationshipentitys individually. when retrieve start or end entity relationship set empty.
i have tried forcing eager fetching no joy.
can see doing wrong here?
my entity...
@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 , 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 test.... (fails on final assert)
@test @rollback(false) public void testaddrelationship(){ thing thinga = new thing(); template.save(thinga); thing retrievedthinga = template.findone(thinga.getnodeid(), thing.class); //returns thing ok assertnotnull(retrievedthinga); thing thingb = new thing(); template.save(thingb); thing retrievedthingb = template.findone(thingb.getnodeid(), thing.class); //returns 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 assert fails "expected 1 found 0" :( should returned entity not have relationsipentity present since eagerly fetching?
the issue below line
@relatedtovia(type="some default type", direction = direction.both) set<thingrelationship> relationships = new hashset<thingrelationship>();
changing below works.
@relatedtovia(type="really_really_likes", direction = direction.both) set<thingrelationship> relationships = new hashset<thingrelationship>();
not sure why doesn't work if using dynamic relationships.
Comments
Post a Comment