在neo4j OGM中,是否有一种方法可以在不同种类的节点之间映射相同的@RelationshipEntity
。
例如,让我们考虑3个节点实体:
@NodeEntity(label = "STATE")
@JsonSnakeCase
public class StateEntity extends BaseEntity {
@Relationship(type = "CONTAINS")
private CityEntity cityEntity;
public CityEntity getCityEntity() {
return cityEntity;
}
public void setCityEntity(CityEntity cityEntity) {
this.cityEntity = cityEntity;
}
}
@NodeEntity(label = "CITY")
@JsonSnakeCase
public class CityEntity extends BaseEntity {
private String cityName;
@Relationship(type = "CONTAINS",direction = Relationship.INCOMING)
private StateEntity stateEntity;
@Relationship(type = "CONTAINS")
private List<BranchEntity> branchEntities;
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public StateEntity getStateEntity() {
return stateEntity;
}
public void setStateEntity(StateEntity stateEntity) {
this.stateEntity = stateEntity;
}
public List<BranchEntity> getBranchEntities() {
return branchEntities;
}
public void setBranchEntities(List<BranchEntity> branchEntities) {
this.branchEntities = branchEntities;
}
}
@NodeEntity(label = "BRANCH")
@JsonSnakeCase
public class BranchEntity extends BaseEntity {
@Relationship(type = "CONTAINS",direction = Relationship.INCOMING)
private CityEntity cityEntity;
}
我想用相同的@RelationEntity
说CONTAINS
映射所有实体(州,城市和分支):
@RelationshipEntity(type = "CONTAINS")
public class Contains extends BaseRelationshipEntity {
@StartNode
StateEntity start;
@EndNode
CityEntity end;
}
但是OGM只允许我在州和城市之间添加关系,我应该如何编写OGM以在多种类型的节点之间创建相同的RelationshipEntity
?
还是我需要为此RelationshipEntity
制作多个副本??
答案 0 :(得分:0)
是的,使用Neo4j OGM可以实现。如果您在一类中具有多个相同类型的关系,OGM将查看目标类型并进行区分。
文档部分