我正在设计一个信标网络,其中信标彼此相邻,使用Neo4j数据库,其中有一个实体和一个关系类。我需要检索两个信标之间的关系,但不知道如何检索。下面是两个类
Beacon类
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();
}任何帮助都是非常感谢的。
发布于 2019-08-08 09:49:20
您需要使用return *或return a, b, c,这样OGM才能推断出将查询响应映射到对象模型所需的所有细节。
查询在Neo4j浏览器中工作的原因是它会自动修改查询以展开相邻路径,在本例中为信标对象。
https://stackoverflow.com/questions/57403807
复制相似问题