Neo4j RelationshipEntity StackOverflow

时间:2017-07-09 20:16:54

标签: spring neo4j spring-data-neo4j-4

我无法理解@RelationshipEntity的工作原理。我尝试过以下示例,但即使我认为我遵循与示例相同的模式,我最终还是有了stackoverflow,因为关系实体抓住了NodeEntity,它具有RelationshipEntity,并且依次打开...

我的模特是: (:Vendor)-[:BELONGS_TO {active: true, sinceDate: date}]->(:Store)

所以我的两个节点是供应商和商店:

@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;
}

我的基础是电影示例,它有(:人物) - [:ACTED_IN] - &gt;(:MOVIE),而且acted_in关系是ROLE

当我调用存储库方法findByVendorId

时会发生这种情况
@Repository
public interface VendorRepository extends GraphRepository<Vendor> {
    List<Vendor> findByVendorId(Long vendorId);
}

1 个答案:

答案 0 :(得分:1)

如果您从两端引用它,则需要引用关系实体,而不是直接引用节点实体。

Store看起来不错,但Vendor包含

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

什么时候应该

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