-
Notifications
You must be signed in to change notification settings - Fork 617
Improve handling of non-distinct collections and already visited objects. #2355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi. Would you please share the domain or the excerpt of it causing the issues? Thank you. |
The problem occurs if you have two I've tried with immutable and mutable, I've tried using a @Node
public class User {
@Id
private final Long id;
@Version
private final Long version;
@Relationship(direction = Relationship.Direction.OUTGOING, type = "FRIEND")
private List<User> friends = new ArrayList<>();
@Relationship(direction = Relationship.Direction.OUTGOING, type = "FAMILY")
private List<User> family = new ArrayList<>();
public User(Long id, Long version) {
this.id = id;
this.version = version;
}
public Long getId() {
return this.id;
}
public Long getVersion() {
return this.version;
}
public List<User> getFriends() {
return this.friends;
}
public List<User> getFamily() {
return this.family;
}
public void addFamily(User user) {
this.family.add(user);
}
public void remveFamily(User user) {
this.family.remove(user);
}
public void addFriend(User user) {
this.friends.add(user);
}
public void removeFriend(User user) {
this.friends.remove(user);
}
} |
Thanks for sharing. On it. |
One workaround is to use
like this, which will correctly update u2 as well… |
To produce the above I first ran: this.repo.save(new User(1L, 0L)).block();
this.repo.save(new User(2L, 0L)).block(); Then ran: var user1 = this.repo.findById(1L).block();
var user2 = this.repo.findById(2L).block();
user1.addFriend(user2);
user2.addFriend(user1);
this.repo.save(user1).block(); |
…sited objects. This commit started as a bunch of tests that should show which self-referential relationships with optimistic locking are supported. The bug in #2355 could be reproduced with the `saveAll` call: The underlying issue bieng that one or more items had been visited at least twice: The first time as related object, than as root. The next root of course still be on the old version. That has been fixed by keeping the state machine tracking visited items for the duration of the `saveAll` calls around. Thus an related object will not be updated twice. For all of this to work in the most efficient way possible, a `java.util.Set` should be used for related objects, along with a valid `equals/hashCode` pair. This is however neglected. By adding an additional check in the state machine falling back to ID extraction, we can improve the user experience a lot and remove that need in many cases. This commit fixes #2355.
…sited objects. This commit started as a bunch of tests that should show which self-referential relationships with optimistic locking are supported. The bug in #2355 could be reproduced with the `saveAll` call: The underlying issue bieng that one or more items had been visited at least twice: The first time as related object, than as root. The next root of course still be on the old version. That has been fixed by keeping the state machine tracking visited items for the duration of the `saveAll` calls around. Thus an related object will not be updated twice. For all of this to work in the most efficient way possible, a `java.util.Set` should be used for related objects, along with a valid `equals/hashCode` pair. This is however neglected. By adding an additional check in the state machine falling back to ID extraction, we can improve the user experience a lot and remove that need in many cases. This commit fixes #2355.
Hi. This is fixed. Thanks a lot for reporting this issue, I think the improvements made here are super valueable. |
When saving two nodes with version properties that reference each other, an
OptimisticLockingFailureException
is thrown upon callingsave
. This only occurs when saving with two pre-existing nodes, if you create two new nodes with a cyclic relationship or create one new node and use one pre-existing node it works.The exception is thrown in
ReactiveNeo4jTemplate::saveRelatedNode
, inside ofThe text was updated successfully, but these errors were encountered: