SDN 4 RelationshipEntity内部的NodeEntity集合

时间:2016-08-09 09:52:07

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

我想创建一个关注@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;

}

1 个答案:

答案 0 :(得分:2)

Neo4j的基础原则是:节点,属性和关系。

  • 节点可以具有属性和关系。
  • 关系可以拥有属性。

将一组实体添加到关系中就像一个有关系的关系。不可能。

你可能可以使用属性和@Convert使用OGM伪造它,但是,也许最好不要违背系统的内容,并寻找另一种方法来建模你的域。

可能还有其他方法可以解决性能问题。或许提出另一个专门描述所面临的性能问题的问题。