@@ -52,15 +52,17 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
52
52
53
53
54
54
/**
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.
64
66
* @see org.eclipse.persistence.sessions.UnitOfWork#beginEarlyTransaction()
65
67
*/
66
68
public void setLazyDatabaseTransaction (boolean lazyDatabaseTransaction ) {
@@ -72,11 +74,10 @@ public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) {
72
74
public Object beginTransaction (EntityManager entityManager , TransactionDefinition definition )
73
75
throws PersistenceException , SQLException , TransactionException {
74
76
75
- UnitOfWork uow = entityManager .unwrap (UnitOfWork .class );
76
-
77
77
if (definition .getIsolationLevel () != TransactionDefinition .ISOLATION_DEFAULT ) {
78
78
// Pass custom isolation level on to EclipseLink's DatabaseLogin configuration
79
79
// (since Spring 4.1.2)
80
+ UnitOfWork uow = entityManager .unwrap (UnitOfWork .class );
80
81
uow .getLogin ().setTransactionIsolation (definition .getIsolationLevel ());
81
82
}
82
83
@@ -85,7 +86,7 @@ public Object beginTransaction(EntityManager entityManager, TransactionDefinitio
85
86
if (!definition .isReadOnly () && !this .lazyDatabaseTransaction ) {
86
87
// Begin an early transaction to force EclipseLink to get a JDBC Connection
87
88
// so that Spring can manage transactions with JDBC as well as EclipseLink.
88
- uow .beginEarlyTransaction ();
89
+ entityManager . unwrap ( UnitOfWork . class ) .beginEarlyTransaction ();
89
90
}
90
91
91
92
return null ;
0 commit comments