public class EclipseLinkJpaDialect extends DefaultJpaDialect
JpaDialect
implementation for Eclipse
Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.7;
backwards-compatible with EclipseLink 2.5 and 2.6 at runtime.
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
their impact. If this is not needed, set the "lazyDatabaseTransaction" flag to
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.
setLazyDatabaseTransaction(boolean)
,
LazyConnectionDataSourceProxy
,
Serialized FormConstructor and Description |
---|
EclipseLinkJpaDialect() |
Modifier and Type | Method and Description |
---|---|
Object |
beginTransaction(EntityManager entityManager,
TransactionDefinition definition)
This implementation invokes the standard JPA
Transaction.begin
method. |
ConnectionHandle |
getJdbcConnection(EntityManager entityManager,
boolean readOnly)
This implementation always returns
null ,
indicating that no JDBC Connection can be provided. |
void |
setLazyDatabaseTransaction(boolean lazyDatabaseTransaction)
Set whether to lazily start a database resource transaction within a
Spring-managed EclipseLink transaction.
|
cleanupTransaction, prepareTransaction, releaseJdbcConnection, translateExceptionIfPossible
public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction)
By default, read-only transactions are started lazily but regular non-read-only transactions are started early. This allows for reusing the same JDBC Connection throughout an entire EclipseLink transaction, for enforced isolation and consistent visibility with JDBC access code working on the same DataSource.
Switch this flag to "true" to enforce a lazy database transaction begin 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.
UnitOfWork.beginEarlyTransaction()
@Nullable public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException
DefaultJpaDialect
Transaction.begin
method. Throws an InvalidIsolationLevelException if a non-default isolation
level is set.
This implementation does not return any transaction data Object, since there
is no state to be kept for a standard JPA transaction. Hence, subclasses do not
have to care about the return value (null
) of this implementation
and are free to return their own transaction data Object.
beginTransaction
in interface JpaDialect
beginTransaction
in class DefaultJpaDialect
entityManager
- the EntityManager to begin a JPA transaction ondefinition
- the Spring transaction definition that defines semanticsJpaDialect.cleanupTransaction(java.lang.Object)
). May implement the
SavepointManager
interface.PersistenceException
- if thrown by JPA methodsSQLException
- if thrown by JDBC methodsTransactionException
- in case of invalid argumentsEntityTransaction.begin()
,
InvalidIsolationLevelException
,
DefaultJpaDialect.cleanupTransaction(java.lang.Object)
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException
DefaultJpaDialect
null
,
indicating that no JDBC Connection can be provided.getJdbcConnection
in interface JpaDialect
getJdbcConnection
in class DefaultJpaDialect
entityManager
- the current JPA EntityManagerreadOnly
- whether the Connection is only needed for read-only purposesreleaseJdbcConnection
,
or null
if no JDBC Connection can be retrievedPersistenceException
- if thrown by JPA methodsSQLException
- if thrown by JDBC methodsJpaDialect.releaseJdbcConnection(org.springframework.jdbc.datasource.ConnectionHandle, javax.persistence.EntityManager)
,
ConnectionHandle.getConnection()
,
SimpleConnectionHandle
,
JpaTransactionManager.setDataSource(javax.sql.DataSource)