我正在設計一個信標網絡,其中信標彼此相鄰,使用 Neo4j 數據庫,其中它具有一個實體和一個關系類。我需要檢索兩個信標之間的關系,但無法弄清楚如何。這是兩個類燈塔類public class Beacon { @Id private String MAC; private String description; private String location; @Relationship(type = "ADJACENT") private List<Adjacent> adjacentList = new ArrayList<>(); public Beacon() { } public Beacon(String MAC, String description, String location) { this.MAC = MAC; this.description = description; this.location = location; } public void addAdjacency(Adjacent adjacent){ if (this.adjacentList==null){ this.adjacentList=new ArrayList<>(); } this.adjacentList.add(adjacent); }//Getters and Setters are excluded}相鄰關系類public class Adjacent { @Id @GeneratedValue private Long id; private int angle; private int cost; @StartNode private Beacon startBeacon; @EndNode private Beacon endBeacon; public Adjacent() { } public Adjacent(int angle, int cost, Beacon startBeacon, Beacon endBeacon) { this.angle = angle; this.cost = cost; this.startBeacon = startBeacon; this.endBeacon = endBeacon; }//Getters and Setters are excluded}我已經嘗試創建一個存儲庫并進行檢索,但即使查詢在 Neo4j 瀏覽器中有效,它也不會在此處檢索任何數據,只是空白括號。public interface AdjacentRepository extends Neo4jRepository<Adjacent,Long> {@Query("match (b:Beacon{MAC:\"f:f:f:f\"})-[a:ADJACENT]-(c:Beacon{MAC:\"r:r:r:r\") return a") Adjacent findaRelationshipp();}任何幫助是極大的贊賞。
1 回答

犯罪嫌疑人X
TA貢獻2080條經驗 獲得超4個贊
您需要return *
,否則return a, b, c
OGM 可以推斷出將查詢響應映射到您的對象模型所需的所有詳細信息。
查詢在 Neo4j 瀏覽器中起作用的原因是因為它會自動修改您的查詢以擴展相鄰路徑,在本例中為 Beacon 對象。
添加回答
舉報
0/150
提交
取消