Neo4j 关系实体 StackOverflow
Neo4j RelationshipEntity StackOverflow
我无法理解@RelationshipEntity 的工作原理。我尝试了以下示例,但即使我认为我遵循与示例相同的模式,我最终还是遇到了计算器溢出,因为关系实体获取了具有关系实体的 NodeEntity,等等......
我的模型是:
(:Vendor)-[:BELONGS_TO {active: true, sinceDate: date}]->(:Store)
所以我的两个节点是 Vendor 和 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(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;
}
我基于具有 (:Person)-[:ACTED_IN]->(:MOVIE) 的电影示例,并且 acted_in 关系是 ROLE
这是在我调用存储库方法 findByVendorId 时发生的
@Repository
public interface VendorRepository extends GraphRepository<Vendor> {
List<Vendor> findByVendorId(Long vendorId);
}
如果从两端引用它,则需要引用关系实体,而不是直接引用节点实体。
Store
看起来不错,但 Vendor
包含
@Relationship(type = "BELONGS_TO")
private Collection<Store> store;
什么时候应该
@Relationship(type = "BELONGS_TO")
private Collection<StoreParticipant> store;
我无法理解@RelationshipEntity 的工作原理。我尝试了以下示例,但即使我认为我遵循与示例相同的模式,我最终还是遇到了计算器溢出,因为关系实体获取了具有关系实体的 NodeEntity,等等......
我的模型是:
(:Vendor)-[:BELONGS_TO {active: true, sinceDate: date}]->(:Store)
所以我的两个节点是 Vendor 和 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(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;
}
我基于具有 (:Person)-[:ACTED_IN]->(:MOVIE) 的电影示例,并且 acted_in 关系是 ROLE
这是在我调用存储库方法 findByVendorId 时发生的
@Repository
public interface VendorRepository extends GraphRepository<Vendor> {
List<Vendor> findByVendorId(Long vendorId);
}
如果从两端引用它,则需要引用关系实体,而不是直接引用节点实体。
Store
看起来不错,但 Vendor
包含
@Relationship(type = "BELONGS_TO")
private Collection<Store> store;
什么时候应该
@Relationship(type = "BELONGS_TO")
private Collection<StoreParticipant> store;