Skip to content
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

Bug: save with cascade of @OneToOne + @Version model sets version to 1 #2558

Merged

Conversation

AlexWagner
Copy link
Contributor

When saving a model, that contains a @OnetoOne Model with @Version, the child models' version will be set to 1.
Then, when the child model will be saved, a OptimisticLockException occures due to the wrong version.
(see test)

Furthermore the 'child'-model also has to have a xToMany-Relation to another model, so that the flag 'saveRecurseSkippable' in BeanPropertyAssoc is set to false.

@@ -360,7 +360,7 @@ public void setForceUpdate(boolean forceUpdate) {
* Return true if the entity should be updated.
*/
public boolean isUpdate() {
return forceUpdate || state == STATE_LOADED;
return forceUpdate || state == STATE_LOADED || state == STATE_REFERENCE;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our oppinion this would be the fix.
Why would you want to insert a reference-bean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with this fix. Thanks

@rbygrave
Copy link
Member

Apologies for taking a while to look at this.

@rbygrave rbygrave merged commit fa0336a into ebean-orm:master Feb 22, 2022
@rbygrave rbygrave added this to the 12.15.1 milestone Feb 22, 2022
@rbygrave rbygrave added the bug label Feb 22, 2022
@rPraml rPraml deleted the bug-save-one-to-one-version-cascade branch February 25, 2022 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants