3

I've four pojos related by unique relationship.
First Employee node:

@NodeEntity
public class Employee {

    @GraphId
    private Long id;

    @Index(unique = true)
    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?

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
Abhinab Kanrar
  • 1,532
  • 2
  • 20
  • 46

1 Answers1

1

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
Lionel Cichero
  • 553
  • 4
  • 17