我想创建一个关注@RelationshipEntity:
@RelationshipEntity(type = "VOTE_GROUP")
public class VoteGroup{
@GraphId
private Long id;
@StartNode
private Decision decision;
@EndNode
private Criterion criterion;
private Object value;
}
和@NodeEntity:
@NodeEntity
public class Vote extends Authorable {
private final static String CONTAINS = "CONTAINS";
private double weight;
private String description;
}
是否可以将Vote
的集合添加到我的VoteGroup
关系实体中?像这样的东西:
@RelationshipEntity(type = "VOTE_GROUP")
public class VoteGroup{
@GraphId
private Long id;
@StartNode
private Decision decision;
@EndNode
private Criterion criterion;
private Object value;
private Set<Vote> votes = new HashSet<>();
}
会起作用吗?如果是这样,我以后能够获得这个投票列表吗?将它们分页?
我之所以会这样问:
现在,在我当前的实现中,我有一个独立的VoteGroup
实体,但Vote
/ VoteGroup
创建的效果非常慢,所以这就是为什么我要寻找一个新方法如何解决它。
@NodeEntity
public class VoteGroup extends BaseEntity {
private static final String VOTED_ON = "VOTED_ON";
private final static String VOTED_FOR = "VOTED_FOR";
private final static String CONTAINS = "CONTAINS";
@Relationship(type = VOTED_FOR, direction = Relationship.OUTGOING)
private Decision decision;
@Relationship(type = VOTED_ON, direction = Relationship.OUTGOING)
private Criterion criterion;
@Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
private Set<Vote> votes = new HashSet<>();
private double avgVotesWeight;
private long totalVotesCount;
}
答案 0 :(得分:2)
Neo4j的基础原则是:节点,属性和关系。
将一组实体添加到关系中就像一个有关系的关系。不可能。
你可能可以使用属性和@Convert
使用OGM伪造它,但是,也许最好不要违背系统的内容,并寻找另一种方法来建模你的域。
可能还有其他方法可以解决性能问题。或许提出另一个专门描述所面临的性能问题的问题。