4
我正在創建它們之間的實體和RelationshipEntitys。我將RelationshipEntitys放置在一個實體中,然後保存實體。這也會自動保存RelationshipEntity。春季數據Neo4j未填充RelationshipEntity
我知道關係已經保存,因爲我可以分別檢索實體和RelationshipEntity。但是,當我檢索開始或結束實體時,它的關係集是空的。
我已經試過迫使渴望,但沒有喜悅。
任何人都可以看到我在這裏做錯了嗎?
我的實體...
@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;
}
...
}
我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;
}
,最後我的測試......(對最終斷言失敗)
@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
}
的最終斷言與「預期1但是找到0」失敗:( 如果返回的實體沒有關係E因爲我急於提取而出現的實體?
你是對的謝謝。不幸的是這給我帶來了另一個問題。我不想有一個默認類型(或者我希望能夠像我一樣嘗試改變它),因爲我希望動態設置該集合中的每個關係。沒有這個我覺得Spring Data Neo4j是相當有限的。任何人有任何想法的工作? –