Skip to content

Commit

Permalink
Document limited isolation level support for concurrent transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jun 13, 2023
1 parent 4b55333 commit 3c2590d
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@
* Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.7;
* backwards-compatible with EclipseLink 2.5 and 2.6 at runtime.
*
* <p>By default, this class acquires an early EclipseLink transaction with an early
* JDBC Connection for non-read-only transactions. This allows for mixing JDBC and
* JPA/EclipseLink operations in the same transaction, with cross visibility of
* <p>By default, this dialect acquires an early EclipseLink transaction with an
* early JDBC Connection for non-read-only transactions. This allows for mixing
* JDBC and JPA operations in the same transaction, with cross visibility of
* their impact. If this is not needed, set the "lazyDatabaseTransaction" flag to
* {@code true} or consistently declare all affected transactions as read-only.
* As of Spring 4.1.2, this will reliably avoid early JDBC Connection retrieval
* and therefore keep EclipseLink in shared cache mode.
*
* <p><b>NOTE: This dialect supports custom isolation levels with limitations.</b>
* Consistent isolation level handling is only guaranteed when all Spring transaction
* definitions specify a concrete isolation level, without any default transactions
* running concurrently. Otherwise, you may see non-default isolation levels exposed
* to default transactions when custom isolation is used in concurrent transactions.
*
* @author Juergen Hoeller
* @since 2.5.2
* @see #setLazyDatabaseTransaction
Expand Down Expand Up @@ -85,7 +91,8 @@ public Object beginTransaction(EntityManager entityManager, TransactionDefinitio
// (since Spring 4.1.2 / revised in 5.3.28)
UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
DatabaseLogin databaseLogin = uow.getLogin();
// Synchronize on shared DatabaseLogin instance (-> concurrent transactions)
// Synchronize on shared DatabaseLogin instance for consistent isolation level
// set and reset in case of concurrent transactions with different isolation.
synchronized (databaseLogin) {
int originalIsolationLevel = databaseLogin.getTransactionIsolation();
// Apply current isolation level value, if necessary.
Expand Down

0 comments on commit 3c2590d

Please sign in to comment.