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

Configuration property to make transaction mandatory even for read operations #34016

Closed
HerrDerb opened this issue Jun 13, 2023 · 7 comments · Fixed by #45784
Closed

Configuration property to make transaction mandatory even for read operations #34016

HerrDerb opened this issue Jun 13, 2023 · 7 comments · Fixed by #45784
Labels
area/hibernate-orm Hibernate ORM good first issue Good for newcomers kind/enhancement New feature or request
Milestone

Comments

@HerrDerb
Copy link
Contributor

Description

I recently discovered that I can perform read operations using a Panache repository during a QuarkusTest without an active transaction. This behavior took me by surprise, and it also resulted in incorrect data being returned (possibly due to caching. Unfortunately, I couldn't reproduce the issue with a reproducer). As soon as I put an active transaction around the test, everything works as expected. I attempted to find a configuration option to enforce a transaction for read operations, but I was unable to locate a suitable setting.

It seems that setting the TransactionRequirement to STRICT is not a viable solution for me, as it would prevent the Liquibase migration from executing.

Without putting into question that no transaction is required to read, I would like to propose a new configuration property to be able to enforce transactions even for read operation. This way, everyone can use transactions according to their preferences.

Implementation ideas

No response

@HerrDerb HerrDerb added the kind/enhancement New feature or request label Jun 13, 2023
@geoand geoand added area/persistence OBSOLETE, DO NOT USE and removed triage/needs-triage labels Jun 14, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 14, 2023

/cc @DavideD (hibernate-reactive), @Sanne (hibernate-orm,hibernate-reactive), @gavinking (hibernate-reactive), @gsmet (hibernate-orm), @mswatosh (db2), @yrodiere (hibernate-orm)

@yrodiere
Copy link
Member

yrodiere commented Jun 14, 2023

+1 to a setting to disable the request-scoped entity manager in Hibernate ORM (as opposed to the transaction-scoped ones).

See here for the relevant runtime code:

} else if (Arc.container().requestContext().isActive()) {
RequestScopedSessionHolder requestScopedSessions = this.requestScopedSessions.get();
return new SessionResult(requestScopedSessions.getOrCreateSession(unitName, sessionFactory),
false, false);

Personally, I'd even consider disabling the request-scoped entity manager by default in the next major version of Quarkus. There are very few, if any, reasons for using Hibernate ORM without transactions, and IMO that should be opt-in for people who really need it.

@HerrDerb
Copy link
Contributor Author

@yrodiere I am with you about the opt in👍

@yrodiere yrodiere added area/hibernate-orm Hibernate ORM and removed area/persistence OBSOLETE, DO NOT USE labels Aug 13, 2024
@HerrDerb
Copy link
Contributor Author

@yrodiere This seems not have any traction, therefor it might be closed. What is your opinion?

@yrodiere yrodiere added the good first issue Good for newcomers label Jan 2, 2025
@yrodiere
Copy link
Member

yrodiere commented Jan 2, 2025

Thanks for the reminder.

This seems worth doing and not terribly complicated to implement; the Quarkus team just didn't get to doing it because of other priorities.

I'll mark as good first issue, so if you or someone else have spare time, they can give it a try :)

@IvanPetkov23
Copy link
Contributor

I’m interested in working on this issue. Could you provide more details on what’s needed?

@yrodiere
Copy link
Member

Great, thanks for considering a contribution!

See the issue description, and feel free to ask question if something is not clear.

I also commented with some hints as to where the check could be implemented:

See here for the relevant runtime code:

quarkus/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/session/TransactionScopedSession.java

Lines 102 to 105 in 2c0cfbd
} else if (Arc.container().requestContext().isActive()) {
RequestScopedSessionHolder requestScopedSessions = this.requestScopedSessions.get();
return new SessionResult(requestScopedSessions.getOrCreateSession(unitName, sessionFactory),
false, false);

Personally, I'd even consider disabling the request-scoped entity manager by default in the next major version of Quarkus. There are very few, if any, reasons for using Hibernate ORM without transactions, and IMO that should be opt-in for people who really need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM good first issue Good for newcomers kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants