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

#3295 Clear PersistenceContext on execution of bulk updates or deletes #3301

Merged
merged 4 commits into from
Feb 15, 2024

Conversation

rbygrave
Copy link
Member

@rbygrave rbygrave commented Jan 8, 2024

Using SqlUpdate or an ORM Update query clear the appropriate part of the PersistenceContext. The effect is that ORM queries executed after a bulk update will effectively load a fresh copy of the data from the database and will not reuse an instance from the persistence context if the bean in question had already been loaded.

Using SqlUpdate or an ORM Update query clear the appropriate part of
the PersistenceContext. The effect is that ORM queries executed after
a bulk update will effectively load a fresh copy of the data from the
database and will not reuse an instance from the persistence context
if the bean in question had already been loaded.
@jnehlmeier
Copy link

bean2 and bean5 should be the same which could be asserted as well.

Before merging this we might want to think about JPA again. I am not 100% sure but I think this change could cause trouble for people who have migrated to ebean using your JPA mode. If the per transaction entity cache works differently in ebean as in JPA this could lead to hard to diagnose side effects.

…ontext

Also make improvements to the test asserts in TestPersistenceContextQueryScope
@rbygrave
Copy link
Member Author

which could be asserted as well.

Yes nice. I've added that.

could cause trouble for people who have migrated to ebean using your JPA mode

So that mode is called autoPersistUpdates and effectively set on the transaction. I do believe this change does not really work when autoPersistUpdates = true or at least it could be very confusing. For now I've made a change to this PR so that this Persistence Context clearing only occurs when autoPersistUpdates = false.

Hmm.

@rbygrave
Copy link
Member Author

I'm feeling comfortable that this PR should be merged in with the next major version (so 14).

JPA mode / autoPersistUpdates = true

I'm feeling some regret about adding that feature. Also just to say Gavin is keen on getting "Stateless Session" functionality into JPA 4 which is all about explicit insert, update, delete etc.

@rbygrave rbygrave added this to the 14.0.0 milestone Jan 18, 2024
@rbygrave rbygrave merged commit 08e8402 into master Feb 15, 2024
2 checks passed
@rbygrave rbygrave deleted the feature/3295-PC-clear-on-bulk-update branch February 15, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updates are not seen inside transaction created using beginTransaction() (until commit)
2 participants