在 Spring 数据 Neo4j 中查询关系
Querying a Relationship in Spring Data Neo4j
我正在设计一个信标网络,其中信标彼此相邻,使用 Neo4j 数据库,其中它具有一个实体和一个关系 class。我需要检索两个信标之间的关系,但无法弄清楚如何。这是两个 classes
信标Class
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
}
邻接关系Class
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();
}
非常感谢任何帮助。
您需要 return *
或 return a, b, c
以便 OGM 可以推断将查询响应映射到您的对象模型所需的所有详细信息。
查询在 Neo4j 浏览器中起作用的原因是它会自动修改您的查询以扩展相邻路径,在本例中为 Beacon 对象。
我正在设计一个信标网络,其中信标彼此相邻,使用 Neo4j 数据库,其中它具有一个实体和一个关系 class。我需要检索两个信标之间的关系,但无法弄清楚如何。这是两个 classes
信标Class
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
}
邻接关系Class
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();
}
非常感谢任何帮助。
您需要 return *
或 return a, b, c
以便 OGM 可以推断将查询响应映射到您的对象模型所需的所有详细信息。
查询在 Neo4j 浏览器中起作用的原因是它会自动修改您的查询以扩展相邻路径,在本例中为 Beacon 对象。