Spring 数据 Neo4j 4 存储库方法 returns 1 个元素

Spring Data Neo4j 4 Repository method returns 1 element

我正在从 SDN 3 迁移到 SDN 4,从 Neo4j 2.3 迁移到 3.0.1

在新的依赖项上,我的测试因断言而失败。它不是 3 个节点,而是 returns 只有一个。

@NodeEntity
public class Decision extends Commentable {

    private final static String CONTAINS = "CONTAINS";
    private final static String DEFINED_BY = "DEFINED_BY";
    private final static String VOTED_FOR = "VOTED_FOR";

    private String name;

    @Relationship(type = DEFINED_BY, direction = Relationship.INCOMING)
    private Set<Criterion> criteria = new HashSet<>();

....


@NodeEntity
public class Criterion extends Authorable {

    private final static String CONTAINS = "CONTAINS";
    private final static String DEFINED_BY = "DEFINED_BY";

    private String name;

    private String description;

    @Relationship(type = CONTAINS, direction = Relationship.INCOMING)
    private CriterionGroup group;

    @Relationship(type = DEFINED_BY, direction = Relationship.OUTGOING)
    private Decision owner;


@Test
    public void testGetChildDecisionsSortedBySumOfCriteriaAvgVotesWeightWithCoefficients() {
        User user = userService.createUser("test", "test", "test@test.com", null, null);

        final Decision rootDecision1 = decisionDao.create("Root decision1", "Root decision 1 description", null, user);

        final Criterion rootDecision1Criterion1 = criterionDao.create("rootDecision1Criterion1", "rootDecision1Criterion1", rootDecision1, user);
        final Criterion rootDecision1Criterion2 = criterionDao.create("rootDecision1Criterion2", "rootDecision1Criterion2", rootDecision1, user);
        final Criterion rootDecision1Criterion3 = criterionDao.create("rootDecision1Criterion3", "rootDecision1Criterion3", rootDecision1, user);

        assertEquals(3, criterionDao.getCriteriaDefinedByDecision(rootDecision1.getId()).size());

存储库方法:

@Query("MATCH (d:Decision)<-[:DEFINED_BY]-(c:Criterion) WHERE id(d) = {decisionId} RETURN c")
List<Criterion> getCriteriaDefinedByDecision(@Param("decisionId") Long decisionId);

这个问题的原因是什么以及如何解决?

已更新

我发现构造

public Criterion(String name, String description, Decision owner, User author) {
        this.name = name;
        this.description = description;
        this.owner = owner;
        setAuthor(author);
    }

不足以让 SDN 4 创建 ONE_TO_MANY 关联。我还必须添加额外的行,以便将对象添加到父集合。

public Criterion(String name, String description, Decision owner, User author) {
        this.name = name;
        this.description = description;
        this.owner = owner;
        if (owner != null) {
            owner.addCriterion(this);
        }
        setAuthor(author);
    }

我做错了什么?

有同样的问题,尝试从 Criterion

中删除 DEFINED_BY @Relationship
   @NodeEntity
   public class Criterion extends Authorable {

    private final static String CONTAINS = "CONTAINS";
    private final static String DEFINED_BY = "DEFINED_BY";

    private String name;

    private String description;

    @Relationship(type = CONTAINS, direction = Relationship.INCOMING)
    private CriterionGroup group;


}

先创建Criterion,然后将它们连接到Decision