2017-07-09 29 views
0

我无法理解@RelationshipEntity的工作原理。我尝试了下面的例子,但即使我认为我遵循与例子相同的模式,我最终得到了一个stackoverflow,因为关系实体获取了具有RelationshipEntity的NodeEntity,并且...Neo4j RelationshipEntity StackOverflow

我的模式是: (: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] - >(:MOVIE)和acted_in关系是ROLE

这是当我打电话库方法findByVendorId

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

回答

1

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

Store看起来很好,但Vendor包含

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

当它应该是

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

谢谢,试过了,但仍然得到同样的。我最终以vendor-> storeParticipant-> Vendor-> storeParticipant结束。 – Tim