EclipseLinkJpaDialect preserves lazy retrieval of UnitOfWork as far as possible
Issue: SPR-12319
This commit is contained in:
parent
c0747a006a
commit
33d85d2a13
|
@ -52,15 +52,17 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether to lazily start a database transaction within an
|
* Set whether to lazily start a database resource transaction within a
|
||||||
* EclipseLink transaction.
|
* Spring-managed EclipseLink transaction.
|
||||||
* <p>By default, database transactions are started early. This allows
|
* <p>By default, read-only transactions are started lazily but regular
|
||||||
* for reusing the same JDBC Connection throughout an entire transaction,
|
* non-read-only transactions are started early. This allows for reusing the
|
||||||
* including read operations, and also for exposing EclipseLink transactions
|
* same JDBC Connection throughout an entire EclipseLink transaction, for
|
||||||
* to JDBC access code (working on the same DataSource).
|
* enforced isolation and consistent visibility with JDBC access code working
|
||||||
* <p>It is only recommended to switch this flag to "true" when no JDBC access
|
* on the same DataSource.
|
||||||
* code is involved in any of the transactions, and when it is acceptable to
|
* <p>Switch this flag to "true" to enforce a lazy database transaction begin
|
||||||
* perform read operations outside of the transactional JDBC Connection.
|
* even for non-read-only transactions, allowing access to EclipseLink's
|
||||||
|
* shared cache and following EclipseLink's connection mode configuration,
|
||||||
|
* assuming that isolation and visibility at the JDBC level are less important.
|
||||||
* @see org.eclipse.persistence.sessions.UnitOfWork#beginEarlyTransaction()
|
* @see org.eclipse.persistence.sessions.UnitOfWork#beginEarlyTransaction()
|
||||||
*/
|
*/
|
||||||
public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) {
|
public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) {
|
||||||
|
@ -72,11 +74,10 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
|
||||||
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
|
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
|
||||||
throws PersistenceException, SQLException, TransactionException {
|
throws PersistenceException, SQLException, TransactionException {
|
||||||
|
|
||||||
UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
|
|
||||||
|
|
||||||
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
|
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
|
||||||
// Pass custom isolation level on to EclipseLink's DatabaseLogin configuration
|
// Pass custom isolation level on to EclipseLink's DatabaseLogin configuration
|
||||||
// (since Spring 4.1.2)
|
// (since Spring 4.1.2)
|
||||||
|
UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
|
||||||
uow.getLogin().setTransactionIsolation(definition.getIsolationLevel());
|
uow.getLogin().setTransactionIsolation(definition.getIsolationLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
|
||||||
if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) {
|
if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) {
|
||||||
// Begin an early transaction to force EclipseLink to get a JDBC Connection
|
// Begin an early transaction to force EclipseLink to get a JDBC Connection
|
||||||
// so that Spring can manage transactions with JDBC as well as EclipseLink.
|
// so that Spring can manage transactions with JDBC as well as EclipseLink.
|
||||||
uow.beginEarlyTransaction();
|
entityManager.unwrap(UnitOfWork.class).beginEarlyTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue