spring neo4j get two list of different labels but the same relationship
-
21-12-2019 - |
Question
public class Company implements Serializable {
@RelatedTo(type = "REPORT_TO", direction = Direction.INCOMING)
private List<Department> departments;
@RelatedTo(type = "REPORT_TO", direction = Direction.INCOMING)
private List<Company> subCompanies;
In class Company, there are two list with different labels (Department and Company),
but when I use neo4jTemplate.fetch(company.getSubCompanies()), the result is the total of departments and subCompanies. It seems spring-neo4j search results by relationship, and search all the label, not the specific one
So why the departments will return ? And the amazing thing is that
@Override
public List<Company> getSubCompaniesByCompanyId(Long companyId) {
Company company = companyRepository.findOne(companyId);
return neo4jTemplate.fetch(company.getSubCompanies());
}
the chrome console will get the Department bean, how can it convert to Company.......
Add the beans to see the amazing and the console result
The properties has "departmentType", which is the property of Department, but now in the bean of Company..... And I've seen in java, the bean in List is Department!!!
Solution
Did you try to use the annotation attribute: enforceTargetType=true
which should limit the types to the one given in the target. (You might need to use elementClass=Department.class
as well, can't remember exactly)