在Spring数据Neo4j中访问@RelationshipEntiry中的属性

时间:2014-06-23 16:33:13

标签: java spring spring-data-neo4j

我正在使用Neo4j的弹簧数据。 该模型的初始设计如下所示:

@NodeEntity
public class User extends Neo4JBaseNode {
    @RelatedToVia(type = "HAS_DEVICE", elementClass = UserDevice.class, direction =       Direction.OUTGOING)  
    private List<Device> devices;
    .... ommited setters,getters
}



@NodeEntity
public class Device extends Neo4JBaseNode {
    private String type;
    private String manufacturer;
    private String model;
    private String os;
    .... ommited setters,getters
}

@RelationshipEntity(type = "HAS_DEVICE")
public class UserDevice {
   @StartNode
   private User user;
   @EndNode
   private Device device;
   private String deviceToken;
}

当用户从数据库中检索时我需要“deviceToken”,但我不知道如何实现这一点。 非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

也许使用@RelatedToVia注入UserDevices而不是Devices,确保@Fetch(如果需要),然后您就可以访问关系属性以及实体属性。即通常你要么使用

@RelatedTo
Set<Device> ... (if you don't care about the relationship properties)

OR

@RelatedToVia
Set<UserDevice> ... (if you care about the relationship as well as the end nodes)