Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-12-2020 04:57 AM
We ave modelled our business classes as follows :-
We are trying to fetch Student associated with a school and vice-versa but unable to do so.
We have a School and Student node with directed outgoing relation (IS_STUDENT_OF) from school to student with a relationship property fulltime:yes
Model code for School,student and RelationshipEntity
@NodeEntity(label = "STUDENT")
public class Student {
@Id
Long id;
@Property
String name;
@Relationship(type = "IS_STUDENT_OF", direction = Relationship.UNDIRECTED)
@JsonIgnoreProperties("student")
SchoolStudentRelationEntity schoolStudentRelationEntity;
}
@NodeEntity(label = "SCHOOL")
public class School {
@Id
Long id;
@Property
String schoolName;
@Relationship(type = "IS_STUDENT_OF", direction = Relationship.UNDIRECTED)
@JsonIgnoreProperties("school")
SchoolStudentRelationEntity schoolStudentRelationEntity;
}
@RelationshipEntity(type="IS_STUDENT_OF")
public class SchoolStudentRelationEntity {
@Property (name ="FULLTIME")
String fullTime;
@StartNode
School school;
@EndNode
Set<Student> student;
}
06-12-2020 07:08 AM
If you know the direction of the relationship, the problem may be that you're using UNDIRECTED.
06-12-2020 10:07 AM
Can you please let me know how can i fetch the binded relations in both the directions.
I tried by changing undirected to Incoming and Outgoing as well Outgoing works as expected but incoming doesn't
06-13-2020 01:22 PM
The RelationshipEntity
needs to have just a single Student
as @EndNode
declared.
The collection if SchoolStudentRelationEntity
needs to be defined in the School
class.
Side note: Using a List
is more common because a Set
can lead to some problems if you check for existence of a certain object and similar. This is because the elements might get changed in the Set
after they got inserted (e.g. assigning ids) and if the equals
/hashCode
implementations are based on those fields (or there isn't any explicit definition), the entries in the Set
cannot be found anymore although they exist.
06-15-2020 10:12 AM
It took me a while to find the root cause, there is some weird behavior of OGM if we create a RelationshipEntity that doesn't have a Property.
When I deleted those classes from my source code it worked as expected.
All the sessions of the conference are now available online