Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Expect disruption to service on Thursday, Feb. 9!

@RelationshipEntity not working with Relationship.UNDIRECTED

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 {
	Long id;

	String name;

	@Relationship(type = "IS_STUDENT_OF", direction = Relationship.UNDIRECTED)
	SchoolStudentRelationEntity schoolStudentRelationEntity;


@NodeEntity(label = "SCHOOL")
public class School {
	Long id;

	String schoolName;

	@Relationship(type = "IS_STUDENT_OF", direction = Relationship.UNDIRECTED)
	SchoolStudentRelationEntity schoolStudentRelationEntity;

public class SchoolStudentRelationEntity {

	@Property (name ="FULLTIME")
	String fullTime;

	School school;

	Set<Student> student;


Graph Steward

If you know the direction of the relationship, the problem may be that you're using UNDIRECTED.

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

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.

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.