Image I have the following entity: Company and Employee, with spring data neo4j annotation:
Company.java
@NodeEntity(label = "Company")
public class Company {
/**
* Graph ID
*/
@GraphId
private Long id;
......
}
Employee.java
@NodeEntity(label = "Employee")
public class Employee {
/**
* Graph ID
*/
@GraphId
private Long id;
......
}
Then there is the relationship entity for these entities:
@RelationshipEntity(type = "EMPLOY")
public class EmployRel {
/**
* Graph ID
*/
@GraphId
private Long id;
@StartNode
private Company company;
@EndNode
private Employee employee;
......
}
So how to keep the reference in Company
and Person
?
Company.java
@Relationship(type = "EMPLOY", direction = Relationship.OUTGOING)
private Set<EmployRel> employeeRel = new HashSet<>();
OR
@Relationship(type = "EMPLOY", direction = Relationship.OUTGOING)
private Set<Employee> employee = new HashSet<>();
Person.java
@Relationship(type = "EMPLOY", direction = Relationship.INCOMING)
private Company company = new Company();
OR
@Relationship(type = "EMPLOY", direction = Relationship.OUTGOING)
private EmployRel employRel = new EmployRel();