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 enter image description here enter image description here and the console result

enter image description here

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!!! enter image description here enter image description here

Was it helpful?

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top