2016-05-24 76 views
1

我從SDN 3移動到SDN 4和從Neo4j的2.3到3.0.1彈簧數據的Neo4j 4庫方法返回1個元件

在新的依賴我的測試失敗,並斷言。它只返回一個,而不是3個節點。

@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", "[email protected]", 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); 
    } 

是不夠的,爲了創造ONE_TO_MANY協會SDN 4 ..我要以添加對象父集合添加額外的行也。

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); 
    } 

我在做什麼錯?

回答

0

有同樣的問題,請嘗試從Criterion

@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; 


} 

去除DEFINED_BY @Relationship創建Criterion第一,然後將它們連接到Decision

+0

謝謝,但我需要按照我的應用程序的業務邏輯這一領域。它在以前版本的SDN中完美運行..他們爲什麼要改變它? – brunoid

+0

不知道,有同樣的問題。 –