[英]Spring - Neo4j : Class Attribute return Null when there is Relationship Entity
我在Spring Project上創建了3個類。 A,B和C類。A和C類是獨立節點。 B類是AC類的RelationshipEntity。
@NodeEntity
public class A {
@GraphId
private Long graphId;
private String id;
@Relationship(type = "a_has_c", direction = "INCOMING")
private C cData;
public A() {
super();
}
}
@RelationshipEntity(type="a_has_c")
public class B {
@GraphId
private Long graphId;
private String id;
@StartNode
private A a;
@EndNode
private C c;
public B() {
super();
}
}
@NodeEntity
public class C {
@GraphId
private Long graphId;
private String id;
public C() {
super();
}
}
問題是,在創建@RelationshipEntity
節點之前,可以從類A的屬性中檢索cData
信息。但是在創建@RelationshipEntity
,它始終返回Null。
如果要從類A的屬性獲取cData
信息,是否需要始終獲取2次?
我正在使用Spring Boot 1.5.6 Release
和Neo4j Community 3.0.6
A
類中的關系定義
@Relationship(type = "a_has_c", direction = "INCOMING")
private C cData;
應該
@Relationship(type = "a_has_c", direction = "INCOMING")
private B cData;
但這也將為關系實體B
的C c
提供null
,因為Spring Data Neo4j / Neo4j對象圖映射器將以1的深度加載。 此值表示加載有問題的節點,並在關系中查找“一步”。 如果是NodeEntity
加載,那么如果是RelationshipEntity
加載,則在這種情況下不要繼續。
在代碼示例之后,這也寫在本節的文檔中: https : //neo4j.com/docs/ogm-manual/2.1/reference/#reference : annotating- entities: relationship
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.