-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
@OneToMany orphanRemoval not occurring (was: insert instead update on changing @OneToMany field) #2952
Comments
Can you check the release notes of 12.1.1 - https://github.com/ebean-orm/ebean/releases/tag/ebean-12.1.1 I believe this is the change in behavior this issue is referring to. You can confirm that by comparing 12.1.1 and previous version which was 11.45.1 |
We can also review this list: https://github.com/ebean-orm/ebean/issues?q=is%3Aissue+is%3Aclosed+label%3Areason-for-version-bump Closed issues tagged with "reason-for-version-bump" |
Hi Rob, thanks for response. I read these issues, it looks simillary but i think it's not the same problem. There is some correlation maybee. There is difference on generated sql setAttachments() vs. getAttachments().clear() + .add() I added one more attachment to marshaled object to see difference
the first
on save generate
ant throws exception due primary key conflict on attachments id 1 and 2 second
generate
and works as expected GoodsEntity.class have
|
Are you able to identify the version that introduced the behavior change. I believe you are saying that the test still passes with 12.1.1? If so, which version breaks the test? |
I do some mystification in versions, i'm sorry. 11.17.5
setAttachments()
clear()/addAll()
11.22.1
setAttachments()
clear()/addAll()
|
one more info. I have some problems with testing 12.x, setAttachments()
clear()/addAll()
|
While debugging a bit, I found a bit of strangeness in the class SaveManyBeans method removeAssocManyOrphans
Please consider this unit test
|
orphanRemoval was not occurring when a loaded bean had a collection replaced by a new BeanCollection (as opposed to a vanilla collection like java.util.ArrayList). Json marshalling a collection puts beans into BeanCollection and this is part of the test that reproduced this issue.
I have a refactor to merge the handling of this case into the other one so that we get back to:
Yeah, that's another bug there. I have a refactor to fix that by getting rid of that part of the code. |
Fix for @onetomany orphanRemoval not occurring for #2952 #2953
… + non-BeanCollection collection results in hard deletes As noted in comments in #2952 In the internals of SaveManyBeans we have: - BUG: the deleteByParentId is hard delete and does not care for soft delete - YUK: internally we have 3 ways of performing the orphan removal when we really want 2 This change fixes the BUG and fixes the YUK. It does this by removing the special case at: https://github.com/ebean-orm/ebean/blob/ebean-parent-13.11.3/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java#L347-L350 ... and replacing it with the more common orphan removal code used when we do not have BeanCollection modifications. The result of this change is that in SaveManyBeans internals we get back to have 2 ways to remove orphans. - A BeanCollection with modifications: Orphans explicitly deleted using the known elements removed from the collection - All other cases: Orphans as everything NOT in the collection that is going to be updated
#2961 - Followup for #2952 - @onetomany + orphanRemoval + @SoftDelete + non-BeanCollection collection results in hard deletes
Expected behavior
Should work as in 11.x version
DB.save/update should use SQL update not insert
Actual behavior
When changed @onetomany List via setter, ebean generate insert sql query.
When using getter and List clear/ addAll, it is using update.
EDIT by Rob:
No it is NOT using update here with clear/addAll. It IS using an extra delete for the orphans.
Steps to reproduce
io.ebean.DuplicateKeyException: Error when batch flush on sql: insert into attachment (id, goods_entity_id, name, version, when_created, when_modified, created_by, updated_by) values (?,?,?,?,?,?,?,?)
The text was updated successfully, but these errors were encountered: