2014-06-23 31 views
0

我使用Neo4j的彈簧數據。 模型的初步設計看起來象下面這樣:在@RelationshipEntiry中訪問Spring資料中的屬性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

也許使用@RelatedToVia注入UserDevices而不是Devices,確保您@獲取它(如果需要),然後您將有權訪問關係屬性以及實體屬性。即通常你要麼使用

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