簡體   English   中英

Spring-Neo4j:存在關系實體時,類屬性返回Null

[英]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 ReleaseNeo4j 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;

但這也將為關系實體BC 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM