Spring 关系实体的数据 Neo4j 存储库
Spring Data Neo4j Repository for Relationship Entity
我希望像查询 NodeEntity 一样查询 RelationshipEntity。
包装信息:
groupId=org.springframework.data
artifactId=spring-data-neo4j
version=5.1.5.RELEASE
我已经在下面发布了虚拟代码。只要概念清楚,如有错误或错误,请不要介意。
节点实体 (1) -> 员工
@NodeEntity("Employee")
public class Employee{
@Id
@GeneratedValue
Long id;
String name;
// Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Relationship(type = STARTED, direction = Relationship.OUTGOING)
private List<Status> starts = new ArrayList<>();
@Relationship(type = PAUSED, direction = Relationship.OUTGOING)
private List<Status> pause = new ArrayList<>();
@Relationship(type = STOPED, direction = Relationship.OUTGOING)
private List<Status> stops = new ArrayList<>();
@Relationship(type = COMPLETED, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();
// Default Relationship
@Relationship(type = ACTION, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();
}
节点实体 (2) -> 项目
@NodeEntity("Project")
public class Project{
@Id
@GeneratedValue
Long id;
String name;
// Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
关系实体 -> 状态
@RelationshipEntity
public class Status {
@Id
@GeneratedValue
Long id;
String name;
// Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@StartNode
private Employee employee;
@EndNode
private Project project;
}
这个存储库工作得很好
public interface EmployeeRepository extends CrudRepository<Employee, Long> {
Employee findByName(String name);
@Query("MATCH (e:Employee)-[r]->(p:Project) WHERE e.name={empName} AND p.name={prjName} RETURN e ")
Employee getEmployeeWorkingOnProjectId(@Param("empName") String empName, @Param("prjName") String prjName);
}
这个存储库不工作。
getEmployeeWorkingOnProject(String,String) returns NULL
I have made modifications after RETURN
keyword, for example modifying it from RETURN *
to the alias like RETURN e,r,p
and also tried changing the sequence of the alias in the return as well.
I wish to get all the status (edges) associated with the specific employee and the specific project.
public interface StatusRepository extends CrudRepository<Status, Long> {
@Query("MATCH (e:Employee)-[r]->(p:Project) WHERE e.name={empName} AND p.name={prjName} RETURN * ")
Status getEmployeeWorkingOnProject(@Param("empName") String empName, @Param("prjName") String prjName);
/* OR
@Query("MATCH (e:Employee)-[r]->(p:Project) WHERE e.name={empName} AND p.name={prjName} AND r.name={statusName} RETURN * ")
Status getEmployeeWorkingOnProject(@Param("empName") String empName, @Param("prjName") String prjName, @Param("statusName") String statusName)
*/
}
Neo4j 浏览器中的 CYPHER 结果:
(用测试图像替换了真实项目图像)
期望的结果(例如)
{
Status: {
name: ..,
Employee: {
...
},
Project: {
...
}
}
},
{
Status: {
name: ..,
Employee: {
...
},
Project: {
...
}
}
},
..
或
STARTED : {
Employee: {
...
},
Project: {
...
}
},
STOPPED : {
Employee: {
...
},
Project: {
...
}
},
或其他类型的类似结果,其中关系实体包含两个连接节点。
从下面提到的 Employee
(Model/Entity) 中删除特定代码后,我能够使 StatusRepository
工作:
@Relationship(type = STARTED, direction = Relationship.OUTGOING)
private List<Status> starts = new ArrayList<>();
@Relationship(type = PAUSED, direction = Relationship.OUTGOING)
private List<Status> pause = new ArrayList<>();
@Relationship(type = STOPED, direction = Relationship.OUTGOING)
private List<Status> stops = new ArrayList<>();
@Relationship(type = COMPLETED, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();
// Default Relationship
@Relationship(type = ACTION, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();
我希望像查询 NodeEntity 一样查询 RelationshipEntity。
包装信息:
groupId=org.springframework.data
artifactId=spring-data-neo4j
version=5.1.5.RELEASE
我已经在下面发布了虚拟代码。只要概念清楚,如有错误或错误,请不要介意。
节点实体 (1) -> 员工
@NodeEntity("Employee")
public class Employee{
@Id
@GeneratedValue
Long id;
String name;
// Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Relationship(type = STARTED, direction = Relationship.OUTGOING)
private List<Status> starts = new ArrayList<>();
@Relationship(type = PAUSED, direction = Relationship.OUTGOING)
private List<Status> pause = new ArrayList<>();
@Relationship(type = STOPED, direction = Relationship.OUTGOING)
private List<Status> stops = new ArrayList<>();
@Relationship(type = COMPLETED, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();
// Default Relationship
@Relationship(type = ACTION, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();
}
节点实体 (2) -> 项目
@NodeEntity("Project")
public class Project{
@Id
@GeneratedValue
Long id;
String name;
// Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
关系实体 -> 状态
@RelationshipEntity
public class Status {
@Id
@GeneratedValue
Long id;
String name;
// Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@StartNode
private Employee employee;
@EndNode
private Project project;
}
这个存储库工作得很好
public interface EmployeeRepository extends CrudRepository<Employee, Long> {
Employee findByName(String name);
@Query("MATCH (e:Employee)-[r]->(p:Project) WHERE e.name={empName} AND p.name={prjName} RETURN e ")
Employee getEmployeeWorkingOnProjectId(@Param("empName") String empName, @Param("prjName") String prjName);
}
这个存储库不工作。
getEmployeeWorkingOnProject(String,String) returns NULL
I have made modifications after
RETURN
keyword, for example modifying it fromRETURN *
to the alias likeRETURN e,r,p
and also tried changing the sequence of the alias in the return as well.
I wish to get all the status (edges) associated with the specific employee and the specific project.
public interface StatusRepository extends CrudRepository<Status, Long> {
@Query("MATCH (e:Employee)-[r]->(p:Project) WHERE e.name={empName} AND p.name={prjName} RETURN * ")
Status getEmployeeWorkingOnProject(@Param("empName") String empName, @Param("prjName") String prjName);
/* OR
@Query("MATCH (e:Employee)-[r]->(p:Project) WHERE e.name={empName} AND p.name={prjName} AND r.name={statusName} RETURN * ")
Status getEmployeeWorkingOnProject(@Param("empName") String empName, @Param("prjName") String prjName, @Param("statusName") String statusName)
*/
}
Neo4j 浏览器中的 CYPHER 结果:
(用测试图像替换了真实项目图像)
期望的结果(例如)
{
Status: {
name: ..,
Employee: {
...
},
Project: {
...
}
}
},
{
Status: {
name: ..,
Employee: {
...
},
Project: {
...
}
}
},
..
或
STARTED : {
Employee: {
...
},
Project: {
...
}
},
STOPPED : {
Employee: {
...
},
Project: {
...
}
},
或其他类型的类似结果,其中关系实体包含两个连接节点。
从下面提到的 Employee
(Model/Entity) 中删除特定代码后,我能够使 StatusRepository
工作:
@Relationship(type = STARTED, direction = Relationship.OUTGOING)
private List<Status> starts = new ArrayList<>();
@Relationship(type = PAUSED, direction = Relationship.OUTGOING)
private List<Status> pause = new ArrayList<>();
@Relationship(type = STOPED, direction = Relationship.OUTGOING)
private List<Status> stops = new ArrayList<>();
@Relationship(type = COMPLETED, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();
// Default Relationship
@Relationship(type = ACTION, direction = Relationship.OUTGOING)
private List<Status> action = new ArrayList<>();