I am trying to insert the relationships between two nodes in Neo4j. I am using the Neo4J(2.1.8 Community) & spring-data-neo4j(3.3.0.RELEASE).
I am using trying to create the Employee-Manager relationship. This relationship entity is Report. (Both class are given below)
But when I am trying to save the relation ship
Employee manager = new Employee("Dev_manager", "Management");
Employee developer = new Employee("Developer", "Development");
developer.setReportsTo(manager);
developer.relatedTo(manager, "REPORTS_TO")
employeeRepository.save(developer);
I am getting exception as
Exception in thread "main" org.springframework.dao.DataRetrievalFailureException: RELATIONSHIP[0] has no property with propertyKey=" type ".; nested exception is org.neo4j.graphdb.NotFoundException: RELATIONSHIP[0] has no property with propertyKey=" type ".
Can any one please help me that what is exactly wrong in this code.
The same code works after I change the type of relations in Employee as
@RelatedToVia(type = "REPORT_TO", elementClass = Report.class, direction = Direction.INCOMING)
Note: I am using this reference for this tutorial.
Employee.java class
@NodeEntity
public class Employee {
@GraphId
private Long id;
private String name;
private String department;
@Fetch
@RelatedTo(type = "REPORTS_TO")
private Employee reportsTo; //Employee reports to some employee (i.e. Manager).
@Fetch
@RelatedTo(type = "REPORTS_TO", direction = Direction.INCOMING)
Set<Employee> directReport; //All the employees who reports to this particular this employee.
@Fetch
@RelatedToVia(type = "REPORTS_TO", elementClass = Report.class, direction = Direction.INCOMING)
Set<Report> relations = new HashSet<Report>(); // All the incoming relationship entities.
//*** Constructor, Getter-setters and other methods...
}
Report.java class
@RelationshipEntity(type = "REPORTS_TO")
public class Report {
@GraphId
private Long id;
private String title;
@Fetch
@StartNode
private Employee child;
@Fetch
@EndNode
private Employee parent;
//*** Constructor, Getter-setters and other methods...
}
**Update: ** I have created 2 relations using this class structure. And I got the below result.
It looks like it creates 2 relations between the node. 1 is empty relation using reportsTo(ie REPORTS_TO) and another relation using the relations(ie REPORT_TO). Can anyone please update why this is happening?
What's the different between: relations
and directReport
?
I think SDN is just confused with all the duplicate listing of relationships?
Esp. if they are once declared as light relationships without type and once as relationship-entities.
I think for this case it is much clearer and easier to use
template.createRelationshipBetween(employee, manager, "REPORTS_TO");
Or just create, populate and save the relationship-entity Report
.
Otherwise you have to make sure that all collections on all sides are consistent with each other.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.