Here's my nodes :
@NodeEntity
public class User {
@Id
@Index(unique = true)
@GeneratedValue(strategy = UuidStrategy.class)
private String id;
@Relationship(type = "LIKE")
private Collection<Pattern> likedPatterns;
...
}
@NodeEntity
public class Pattern {
@Id
@Index(unique = true)
@GeneratedValue(strategy = UuidStrategy.class)
private String id;
private String name;
@Relationship(type = "LIKE", direction = Relationship.INCOMING)
private List<User> likes;
...
}
I try to delete relationship between user and pattern :
@Override
@Transactional(readOnly = false)
public void deleteLikedPattern(String patternId, Long authId) {
User user = userRepository.findByAuthId(authId);
user.getLikedPatterns().removeIf(p -> p.getId().equals(patternId));
userRepository.save(user);
}
In the begining user has 2 pattern. On debug I can see that patternId is found in pattern collection, and corresponding pattern is removed from the list. Then the save() is done, and I got no error. But if I check in DB, pattern and user are still linked, relationship is still here.
I tried solution on this post Neo4j OGM how to delete relationship which works. Which means that if I want to delete a relationship, I have to delete association in both entities list :
delete pattern from user pattern's collection
delete user from pattern user's collection)
which is a little tedious...
And in many other thread asking for same problem, people seems not to suggest to delete association on both sides. My question is : do I HAVE to delete association on both sides, or should it work by just removing pattern from user's favorites list?
Thx