2017-07-09 3 views
0

@RelationshipEntityがどのように機能するか理解できません。次の例を試してみましたが、例と同じパターンに従っているとは思っていますが、Relationship EntityがRelationshipEntityを持ちNodeEntityを取得しているため、stackoverflowで終わります。Neo4j RelationshipEntity StackOverflow

私のモデルは次のとおりです。 (:Vendor)-[:BELONGS_TO {active: true, sinceDate: date}]->(:Store)

だから私の2つのノードがベンダーと店です:

@NodeEntity 
@Data 
public class Vendor { 

    @GraphId 
    private Long id; 

    private Long vendorId; 

    private String name; 

    private String address; 

    @Relationship(type = "OWNS") 
    private Collection<Inventory> inventory; 

    @Relationship(type = "BELONGS_TO") 
    private Collection<Store> store; 
} 

@NodeEntity 
@Data 
public class Store { 

    @GraphId 
    private Long id; 

    private Long storeId; 

    private String name; 

    private String address; 

    private String email; 

    @Relationship(type = "BELONGS_TO", direction = Relationship.INCOMING) 
    private List<StoreParticipant> storeParticipant; 
} 

そして、私のRelationshipEntity:

@RelationshipEntity(type = "BELONGS_TO") 
@Data 
public class StoreParticipant { 

    @GraphId 
    private Long id; 

    @StartNode 
    private Vendor vendor; 

    @EndNode 
    private Store store; 

    private int count; 

    private double price; 

    private boolean negotiable; 

    private boolean active; 
} 

Iが有していた動画例のオフこれをベース(:人) - [:ACTED_IN] - >(:MOVIE)とacted_in関係がIリポジトリ方法findByVendorId

呼び出すときにこれが起こっているROLE

ました

@Repository 
public interface VendorRepository extends GraphRepository<Vendor> { 
    List<Vendor> findByVendorId(Long vendorId); 
} 

答えて

1

これを両端から参照する場合は、ノードエンティティを直接参照するのではなく、関係エンティティを参照する必要があります。

Storeは正常に見えるが、それは

@Relationship(type = "BELONGS_TO") 
private Collection<StoreParticipant> store; 
+0

おかげであるべきときVendor

@Relationship(type = "BELONGS_TO") private Collection<Store> store; 

が含まれている、ことを試みたが、まだ同じを得ます。私はちょうどベンダー - > storeParticipant - >ベンダー - > storeParticipantで、終わる。 – Tim