2016-07-10 5 views
0

Ich habe eine folgende Spring Data Neo4j 4.2.0.BUILD-snapshot Einheiten:Spring Data Neo4j kehrt Knoten mit leeren Kindknoten

@NodeEntity 
public class VoteGroup extends BaseEntity { 

    private static final String VOTED_ON = "VOTED_ON"; 
    private final static String VOTED_FOR = "VOTED_FOR"; 

    @Relationship(type = VOTED_FOR, direction = Relationship.OUTGOING) 
    private Decision decision; 

    @Relationship(type = VOTED_ON, direction = Relationship.OUTGOING) 
    private Criterion criterion; 
... 
} 

@NodeEntity 
public class Decision extends Commentable { 

    @Relationship(type = VOTED_FOR, direction = Relationship.INCOMING) 
    private Set<VoteGroup> voteGroups = new HashSet<>(); 
... 
} 

@NodeEntity 
public class Criterion extends Authorable { 

    @Relationship(type = VOTED_ON, direction = Relationship.INCOMING) 
    private Set<VoteGroup> voteGroups = new HashSet<>(); 

.... 
} 

Repository:

@Repository 
public interface VoteGroupRepository extends GraphRepository<VoteGroup> { 

    @Query("MATCH (d:Decision)<-[:VOTED_FOR]-(vg:VoteGroup)-[:VOTED_ON]->(c:Criterion) WHERE id(d) = {decisionId} AND id(c) = {criterionId} RETURN vg") 
    VoteGroup getVoteGroupForDecisionOnCriterion(@Param("decisionId") Long decisionId, @Param("criterionId") Long criterionId); 

} 

Ich schaffe VoteGroup mit ein folgender Konstruktor:

public VoteGroup(Decision decision, Criterion criterion, double avgVotesWeight, long totalVotesCount) { 
     this.decision = decision; 
     decision.addVoteGroup(this); 
     this.criterion = criterion; 
     criterion.addVoteGroup(this); 
     this.avgVotesWeight = avgVotesWeight; 
     this.totalVotesCount = totalVotesCount; 
    } 

aber wenn ich versuchezuvor gespeicherte zu findenmit:

VoteGroup voteGroup = getVoteGroupForDecisionOnCriterion(decision.getId(), criterion.getId()); 

meine voteGroup.decision und voteGroup.criterion sind NULL ..

aber wenn ich direkt nach dem findOne Methode aufrufen:

voteGroup = voteGroupRepository.findOne(voteGroup.getId()); 

voteGroup.decision und voteGroup.criterion richtig ausgefüllt.

Was ist falsch mit meiner Repository-Methode/Cypher und wie man es beheben kann?

Antwort

1

Die Abfrage

@Query("MATCH (d:Decision)<-[:VOTED_FOR]-(vg:VoteGroup)-[:VOTED_ON]->(c:Criterion) WHERE id(d) = {decisionId} AND id(c) = {criterionId} RETURN vg") 

gibt nur den VoteGroup Knoten und so, das ist alles, was die OGM abbilden. Wenn Sie die Entscheidung und das Kriterium auch möchten, müssen Sie diese Knoten und ihre Beziehungen zurückgeben. So etwas sollte funktionieren:

@Query("MATCH (d:Decision)<-[for:VOTED_FOR]-(vg:VoteGroup)-[on:VOTED_ON]->(c:Criterion) WHERE id(d) = {decisionId} AND id(c) = {criterionId} RETURN vg,d,for,on,c") 

Dieser Blog-Eintrag weitere Beispiele enthält: http://graphaware.com/neo4j/2016/04/06/mapping-query-entities-sdn.html

BTW der VoteGroup Konstruktor Sie nicht von der OGM geteilt wird verwendet werden, benötigen Sie einen nicht-args-Konstruktor.

Verwandte Themen