In he famous book "Java persistence with Hibernate" we can read the following:
"A persistence context is a cache of persistent entity instances.... Automatic dirty checking is one of the benefits of this caching. Another benefit is repeatable read for entities and the performance advantage of a unit of work-scoped cache... You don’t have to do anything special to enable the persistence context cache. It’s always on and, for the reasons shown, can’t be turned off.
Does this mean that one can never achieve a transaction isolation level "Read uncommitted" with Hibernate?
No, it doesn't. Hibernate offers
application-level repeatable reads
for entities. That's different thanDB-level repeatable reads
which applies to any query.So, if you want a custom isolation level, like
REPEATABLE_READ
for all the queries executed by a given transaction, not just for fetching entities, then you can set it like this:Now, your question title says:
If you are using Oracle and PostgreSQL, you cannot do that since
Read Uncommitted
is not supported, and you'll getREAD_COMMITTED
instead.For SQL Server and MySQL, set it like this: