Difference from version 11 when directly setting a onetomany collection and calling update #3285
Replies: 3 comments 8 replies
-
Yes, you need to use You always have to decide whether or not the But there is also a scenario like Old ebean versions also have an annotation called This might also affect I don't think you will get back the old mode and you would need to carefully update your code. See release notes https://github.com/ebean-orm/ebean/releases/tag/ebean-12.1.1 |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. I do understand the implications of the different types of behavior, however, it is a relatively large legacy code base that I then need to go through on a per annotation basis and see all usages, to see where I am affected by this, if I understand correctly. As far as I can tell the javax.persistence @onetomany implementation in version 11.15.12 still had the orphanRemoval default set to false, but it doesn't actually behave that way. Reading the release notes again, I still cannot see that this was deliberately changed. What I was hoping to ascertain was whether or not I could just set orphanRemoval to true on all the annotations, and then have the same behavior as I do currently, without any other repercussions. It does seem weird to me that default behavior on a @onetomany relationship with cascade = CascadeType.ALL has: behave the same as: My biggest concern is, if the above is true and not a misunderstanding on my part, are there any other changes that have been made in other relationship annotations, specifically @manytomany which doesn't have an attribute of orphanRemoval, but if I recall correctly if I had the following relationship:
Then the following operation: Resulted in: followed by inserting all of the elements in the list. This behavior I remember because we recently had a DuplicateKeyException being thrown in a race condition when adding two separate Respondents in different concurrent transactions with a isolation level of READ_COMMITTED against a postgresql database. When the first transaction commits, the second transaction will not execute the delete, because the rows it was waiting to delete, were deleted by the first transaction (from the postgres doc: If the first updater commits, the second updater will ignore the row if the first updater deleted it), but it will try and add the elements of the collection again, so try to add the existing respondents to the segment once again which are already there causing the exception. |
Beta Was this translation helpful? Give feedback.
-
I think that the PR that fixed this issue: is the main issue that our legacy code is having trouble with. I have a similar relationship as before:
where an update of of an incoming Study object with an existing Segment object in its segments list Before with version 11.15.12 resulted in:
Now produces:
Which results in a DuplicateKeyException. But does this make sense for objects whose @id's are generated as it automatically is with a UUID? If I understand the bug report and the description, this is for when the id's are provided and not generated (is this what is meant by managed id?). I, therefore, tried to add the |
Beta Was this translation helpful? Give feedback.
-
I am in the process of upgrading from version 11.15.12 to 13.25.1, and am confused by a difference of behavior when setting a @onetomany annotated collection directly and calling update.
I have a collection:
An existing parentBlock has 2 existing children.
I directly set the one to many collection to 6 newly created children objects.
Without any code changes -> this is the log output from setting loglevel to TRACE for version 11.15.12:
Where it first deletes all child elements from the parent block and inserts the 6 new elements.
However in version 13.25.1:
Here it just inserts the newly created elements, so when you fetch the parentBlock from the database again, It now has 8 children, instead of the 6 it has been set to.
Is this intended new behavior? And is it possible to make it behave as it used to. Otherwise our legacy code will behave in an incorrect manner.
I suspect that the previous version behaved incorrectly, and is it related to the @onetomany annotation attribute orphanRemoval by default is set to false?
Beta Was this translation helpful? Give feedback.
All reactions