-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Propagate read-only status to Hibernate Session through setDefaultReadOnly [SPR-16956] #21494
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
Comments
MIhalcea Vlad commented Pull Request: #1861 |
Juergen Hoeller commented MIhalcea Vlad, does it make sense to also set each |
Juergen Hoeller commented I've rolled this into For the time being, I'd prefer leaving this as a Hibernate-native feature. After all, as of Hibernate 5.2, |
MIhalcea Vlad commented Hi, Jurgen. I've just seen your question. I would not set the flush mode to Related to your changes, does Spring Boot use the If Spring Boot always picks the |
Juergen Hoeller commented I've added corresponding behavior to As for the flushing question, we were specifically wondering whether an explicit query-level |
MIhalcea Vlad commented That's great to hear. I'll test it once 5.1 RC1 is released. As for the query-level flush setting, I don't see how it could make any difference to the Session-level one. If the Session is set to Thanks for integrating it. |
Neale Upstone commented Juergen Hoeller Would you consider this for backport to 4.3.x? It appears a safe (and sounding significant) performance improvement, which multiplied across many 4.3.x applications would save quite some CPU cycles and energy consumption. Naturally I'm thinking anything that'll help save the snow in Austrian ski resorts. |
Juergen Hoeller commented I'd expect all the Austrian-affecting Spring/Hibernate applications to upgrade to 5.1 immediately in any case ;-) On a serious note, it's actually mostly memory saved here since in a regular Spring read-only transaction no flush is ever being triggered... and even there, it's mostly memory being made available to the GC earlier than before. It might not have much effect in a typical short-lived transaction at all if the GC only kicks in after the transaction in any case. CPU cycles would only really be saved in case of a user-level flush attempt. Ironically this is exactly the problem with backwards-compatibility: If a user tried such a manual All in all, I'm willing to enforce and defend such stricter semantics in a new feature release but I'm not sure that backporting to 4.3.x would be wise here. The JPA part is rather involved to begin with since it needs an extension in the dialect contract and spans a wider range of Hibernate versions in 4.3.x. Even for the native Hibernate part, a backport might cause more hard-to-track harm than noticeable benefit. |
Neale Upstone commented Thanks Juergen Hoeller. I'll just have to push the upgrade forwards in our case. I suspected that might be the answer, but it was worth checking. |
There is conflicting information in the Spring docs, this issue suggests setting readOnly on a transaction didn't previously propagate down to the Hibernate session; however, the Spring Data doc says setting Excerpt (section 2.5.1): "Note Which is it? |
Uh oh!
There was an error while loading. Please reload this page.
MIhalcea Vlad opened SPR-16956 and commented
By default,
@Transactional(readOnly = true)
sets the FlushMode to MANUAL. However, Hibernate can save up lots of memory by discarding the associated hydrated state if we also set thesession.setDefaultReadOnly(true)
.Not only that we save memory, but we also save CPU cycles because, if the user tries to do a manual flush, we won't propagate it to any entity since they are virtually read-only.
Affects: 5.0.7
Issue Links:
Referenced from: pull request #1861, and commits 010ba33, d22d408
0 votes, 5 watchers
The text was updated successfully, but these errors were encountered: