cancel
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 :-

2X_8_80f440a452eda1c3d58142910acb24d47f8fedc3.png

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;

}
4 REPLIES 4

MuddyBootsCode
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.