Hi! I am changing from spring boot 2.3 to 2.4, with that to neo4j 6.
I am rewriting the "RelationshipEntity"s to "RelationshipPropery".
The difference here is that a RelationshipProperty now only has one end of the relation as "TargetNode", instead of "StartNode"/"EndNode".
I read here that a bidirectional relationship in neo4j is also just onedirectional, and the other side is implied.
So now saving for example a Friendship into person1's "FriendshipList", with a targetNode set to person2 will imply the otherside, and person2 will also have a friendship to person1?
Or do i have to set it in both directions as shown below.
As an example:
public class Person{
@Relationship(type = "Friend_With")
List<FriendShip> friendShips;
............
............
}
@RelationshipProperties
@Data
public class FriendShip
{
@Id
@GeneratedValue(generatorClass = UUIDGenerator.class)
private String id;
@TargetNode
private Person personEnd;
private String type = "normal";
public String getClassName()
{
return this.getClass().getName();
}
}
//saving the relationship:
Person person1 = new Person();
Person person2 = new Person();
Friendship friendship1= new Friendship();
friendship1.setTargetnode(person2)
Friendship friendship2= new Friendship();
friendship2.setTargetnode(person1)
person1.getFriendships().add(friendship1);
person2.getFriendships().add(friendship2);
personRepo.saveAll(List.of(person1,person2));
friendshipRepo.saveAll(List.of(friendship1,friendShip2));
Hope it's not too confusing what i mean.
Thanks,
Daniel