Skip to content

Commit 33d85d2

Browse files
committed
EclipseLinkJpaDialect preserves lazy retrieval of UnitOfWork as far as possible
Issue: SPR-12319
1 parent c0747a0 commit 33d85d2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
5252

5353

5454
/**
55-
* Set whether to lazily start a database transaction within an
56-
* EclipseLink transaction.
57-
* <p>By default, database transactions are started early. This allows
58-
* for reusing the same JDBC Connection throughout an entire transaction,
59-
* including read operations, and also for exposing EclipseLink transactions
60-
* to JDBC access code (working on the same DataSource).
61-
* <p>It is only recommended to switch this flag to "true" when no JDBC access
62-
* code is involved in any of the transactions, and when it is acceptable to
63-
* perform read operations outside of the transactional JDBC Connection.
55+
* Set whether to lazily start a database resource transaction within a
56+
* Spring-managed EclipseLink transaction.
57+
* <p>By default, read-only transactions are started lazily but regular
58+
* non-read-only transactions are started early. This allows for reusing the
59+
* same JDBC Connection throughout an entire EclipseLink transaction, for
60+
* enforced isolation and consistent visibility with JDBC access code working
61+
* on the same DataSource.
62+
* <p>Switch this flag to "true" to enforce a lazy database transaction begin
63+
* even for non-read-only transactions, allowing access to EclipseLink's
64+
* shared cache and following EclipseLink's connection mode configuration,
65+
* assuming that isolation and visibility at the JDBC level are less important.
6466
* @see org.eclipse.persistence.sessions.UnitOfWork#beginEarlyTransaction()
6567
*/
6668
public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) {
@@ -72,11 +74,10 @@ public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) {
7274
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
7375
throws PersistenceException, SQLException, TransactionException {
7476

75-
UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
76-
7777
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
7878
// Pass custom isolation level on to EclipseLink's DatabaseLogin configuration
7979
// (since Spring 4.1.2)
80+
UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
8081
uow.getLogin().setTransactionIsolation(definition.getIsolationLevel());
8182
}
8283

@@ -85,7 +86,7 @@ public Object beginTransaction(EntityManager entityManager, TransactionDefinitio
8586
if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) {
8687
// Begin an early transaction to force EclipseLink to get a JDBC Connection
8788
// so that Spring can manage transactions with JDBC as well as EclipseLink.
88-
uow.beginEarlyTransaction();
89+
entityManager.unwrap(UnitOfWork.class).beginEarlyTransaction();
8990
}
9091

9192
return null;

0 commit comments

Comments
 (0)