Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams private String employeeId; @Relationship(type = "HAS_POSITION", direction = Relationship.OUTGOING) private Position position; @Relationship(type = "HAS_SHIFT", direction = Relationship.OUTGOING) private List<ShiftDate> shiftDates = new ArrayList<>(); @Relationship(type = "RESTRICTION_OF_EMPLOYEE", direction = Relationship.INCOMING) private List<Restriction> restrictions = new ArrayList<>(); @Relationship(type = "PREFERENCE_OF_EMPLOYEE", direction = Relationship.INCOMING) private List<Preference> preferences = new ArrayList<>();

As you can see, it has four relationship.
My ShiftDate pojo looks like:

@NodeEntity
public class ShiftDate {
    @GraphId
    private Long id;
    private Date startDt;
    private Date endDt;
    private List<Date> dates = new ArrayList<>();
    @Relationship(type = "HAS_RESTRICTION", direction = Relationship.OUTGOING)
    private List<Restriction> restrictions = new ArrayList<>();
    @Relationship(type = "HAS_PREFERENCE", direction = Relationship.OUTGOING)
    private List<Preference> preferences = new ArrayList<>();

Now, Restriction and Preference:

@NodeEntity
public class Restriction {
    @GraphId
    private Long id;
    private String from;
    private String to;
    private String notes;
@NodeEntity
public class Preference {
    @GraphId
    private Long id;
    private String from;
    private String to;
    private String notes;

The problem is when I'm trying to fetch ShiftDate details from the Employee node, it's returning only ShiftDate data but not the Preference and Restriction Data.

I've tried Spring Data's List<ShiftDate> getShiftDatesByEmployeeId(String employeeId) method which doesn't work.

Tried

@Query("MATCH (employee:Employee{employeeId:{0}})-[has_shift:HAS_SHIFT]->(shiftDate:ShiftDate)
RETURN shiftDate");

still doesn't work. Tried advanced query like

@Query("MATCH (employee:Employee)-[has_shift:HAS_SHIFT]->(shiftDate:ShiftDate)-[has_preference:HAS_PREFERENCE]-> (preference:Preference)
WITH employee,shiftDate,preference
MATCH (shiftDate)-[has_restriction:HAS_RESTRICTION]->(restriction:Restriction) WHERE employee.employeeId={0}
RETURN shiftDate,preference,restriction");

still not working.

Can anybody tell me what's the problem?

You need to return the relations as well, that way SDN will populate your child objects.

Your return clause should look like:

RETURN shiftDate, has_preference, preference, has_restriction, restriction
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.