我正在使用 Neo4j 的 spring 数据。 模型的初始设计如下所示:
@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”,但我不知道如何实现这一点。 非常感谢任何帮助。
最佳答案
也许使用@RelatedToVia来注入(inject)UserDevices而不是Devices,确保你@Fetch它(如果需要),然后你就可以访问关系属性以及实体属性。 IE。通常你会使用
@RelatedTo
Set<Device> ... (if you don't care about the relationship properties)
或者
@RelatedToVia
Set<UserDevice> ... (if you care about the relationship as well as the end nodes)
关于java - 在 Spring 数据 Neo4j 中访问 @RelationshipEntiry 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24370911/