-
Notifications
You must be signed in to change notification settings - Fork 173
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
Duplicate objects in UnitOfWorkImpl.primaryKeyToNewObjects #1950
Comments
Thank you for the report. |
I find it both surprising and scary that this rather basic use case seems to be not covered in EclipseLink unit test suite so far |
@rfelcman Could you please advise on where I should put the UnitTest for this? I think the best place to add the UnitTest would be Also I think we should reconsider whether it is wise to perform the |
As fix is related with |
@rfelcman You are right that the DB is not directly affected, but I still think this is a serious bug. In the example above, the entity is removed from the persistence context before it is ever written to the DB. But the call to Therefore I think a new release with the fix should be published soon. |
One small addition to avoid any confusion: It seems the code snippet I originally posted is a bit too simple and actually shows the correct behaviour. @Test
public void test() {
Entity entity = new Entity();
this.entityManager.persist(entity);
Entity entity2 = new Entity();
this.entityManager.persist(entity2);
Entity savedEntity = this.entityManager.find(Entity.class, entity.getId());
this.entityManager.remove(savedEntity);
savedEntity = this.entityManager.find(Entity.class, entity.getId());
assertThat(savedEntity, nullValue());
} |
* Fixes #1950: Duplicate objects in UnitOfWorkImpl.primaryKeyToNewObjects - no longer add objects to primaryKeyToNewObjects in assignSequenceNumber - use IdentityHashSet instead of ArrayList for primaryKeyToNewObjects to prevent duplicates in the future Signed-off-by: Patrick Schmitt <[email protected]>
@rfelcman is there a timeline for when the new versions with this fix will be published? Since this is a serious bug, I think fixed versions should be published soon. |
Usually we try to make new release every 6 months, if our capacity will allow it. |
Latest 2.7.13 was in July 2023, next one should be Dec-Jan. |
…e4j#1951) * Fixes eclipse-ee4j#1950: Duplicate objects in UnitOfWorkImpl.primaryKeyToNewObjects - no longer add objects to primaryKeyToNewObjects in assignSequenceNumber - use IdentityHashSet instead of ArrayList for primaryKeyToNewObjects to prevent duplicates in the future Signed-off-by: Patrick Schmitt <[email protected]> (cherry picked from commit ad93f7a)
… from master (#2177) * Duplicate objects in UnitOfWorkImpl.primaryKeyToNewObjects (#1951) * Fixes #1950: Duplicate objects in UnitOfWorkImpl.primaryKeyToNewObjects - no longer add objects to primaryKeyToNewObjects in assignSequenceNumber - use IdentityHashSet instead of ArrayList for primaryKeyToNewObjects to prevent duplicates in the future Signed-off-by: Patrick Schmitt <[email protected]> (cherry picked from commit ad93f7a)
When
UnitOfWorkImpl#registerNotRegisteredNewObjectForPersist
is called, the object is potentially added twice to the primaryKeyToNewObjects map.First when the
assignSequenceNumber
method is called (assuming a sequence is used) and a second time when callingregisterNewObjectClone
(which callsaddNewObjectToPrimaryKeyToNewObjects
).When the object is later unregistered, it is only removed once from the map (see
removeObjectFromPrimaryKeyToNewObjects
).Subsequent calls on
EntityManger.find
will still find the remaining object, which should not be the case.The following code snippet illustrates the behaviour:
The assertion fails, because the object is still in UnitOfWorkImpl.primaryKeyToNewObjects as it was added twice but only removed once.
Version affected: 2.7.13
Last version with expected behaviour: 2.7.12
Change introduced with #1843
The text was updated successfully, but these errors were encountered: