0

我有一个这样的 NodeEntity:

@NodeEntity
public class User {

    @GraphId
    private Long id;

    private String name;

    @Fetch
    @RelatedToVia
    private Set<Rel> rels;

    public Rel connectTo(User u, String type) {
        if (this.rels == null) 
            this.rels = new HashSet<Rel>();
        Rel rel = new Rel(this, u, type);
        this.rels.add(rel);
        return rel;
    }
}

和关系实体:

@RelationshipEntity(type="REL")
public class Rel {

    @GraphId
    private Long id;
    @Fetch
    @StartNode
    private User start;
    @Fetch
    @EndNode
    private User end;

    @RelationshipType
    private String type;

    public Rel(){}
    public Rel(User start, User end, String type) {
        this.start = start;
        this.end = end;
        this.type = type;
    }
}

但是当我尝试加载用户时,关系是空的:

User neo = new User();
neo.setName("Neo");

User trinity = new User();
trinity.setName("Trinity");
this.userRepository.save(trinity);

neo.connectTo(trinity, "LOVES");

this.userRepository.save(neo);

User user = this.userRepository.findOne(neo.getId());
// expected:<1> but was:<0>
Assert.assertEquals(1, user.getRels().size());

我可以急切地加载与此节点相关的关系吗?我错过了什么吗?

提前致谢!

4

1 回答 1

0

您可以尝试使用相同的关系类型吗?您的关系实体给出 type="REL",但您将“LOVES”传递给 neo.connectTo() 方法。

于 2013-08-26T04:19:56.157 回答