Class EclipseLinkJpaDialect
- All Implemented Interfaces:
Serializable
,PersistenceExceptionTranslator
,JpaDialect
JpaDialect
implementation for Eclipse
Persistence Services (EclipseLink). Compatible with EclipseLink 3.0/4.0.
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
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.
NOTE: This dialect supports custom isolation levels with limitations.
Consistent isolation level handling is only guaranteed when all Spring transaction
definitions specify a concrete isolation level, and as of 6.0.10 also when using
the default isolation level with non-readOnly and non-lazy transactions. See the
"lazyDatabaseTransaction" javadoc
for details.
- Since:
- 2.5.2
- Author:
- Juergen Hoeller
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbeginTransaction
(EntityManager entityManager, TransactionDefinition definition) This implementation invokes the standard JPATransaction.begin
method.getJdbcConnection
(EntityManager entityManager, boolean readOnly) This implementation always returnsnull
, 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.Methods inherited from class org.springframework.orm.jpa.DefaultJpaDialect
cleanupTransaction, prepareTransaction, releaseJdbcConnection, translateExceptionIfPossible
-
Constructor Details
-
EclipseLinkJpaDialect
public EclipseLinkJpaDialect()
-
-
Method Details
-
setLazyDatabaseTransaction
public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) Set whether to lazily start a database resource transaction within a Spring-managed EclipseLink transaction.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.
NOTE: Lazy database transactions are not guaranteed to work reliably in combination with custom isolation levels. Use read-only as well as this lazy flag with care. If other transactions use custom isolation levels, it is not recommended to use read-only and lazy transactions at all. Otherwise, you may see non-default isolation levels used during read-only or lazy access. If this is not acceptable, don't use read-only and lazy next to custom isolation levels in potentially concurrent transactions.
- See Also:
-
UnitOfWork.beginEarlyTransaction()
TransactionDefinition.isReadOnly()
TransactionDefinition.getIsolationLevel()
-
beginTransaction
@Nullable public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException Description copied from class:DefaultJpaDialect
This implementation invokes the standard JPATransaction.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.- Specified by:
beginTransaction
in interfaceJpaDialect
- Overrides:
beginTransaction
in classDefaultJpaDialect
- Parameters:
entityManager
- the EntityManager to begin a JPA transaction ondefinition
- the Spring transaction definition that defines semantics- Returns:
- an arbitrary object that holds transaction data, if any
(to be passed into
JpaDialect.cleanupTransaction(java.lang.Object)
). May implement theSavepointManager
interface. - Throws:
PersistenceException
- if thrown by JPA methodsSQLException
- if thrown by JDBC methodsTransactionException
- in case of invalid arguments- See Also:
-
getJdbcConnection
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException Description copied from class:DefaultJpaDialect
This implementation always returnsnull
, indicating that no JDBC Connection can be provided.- Specified by:
getJdbcConnection
in interfaceJpaDialect
- Overrides:
getJdbcConnection
in classDefaultJpaDialect
- Parameters:
entityManager
- the current JPA EntityManagerreadOnly
- whether the Connection is only needed for read-only purposes- Returns:
- a handle for the Connection, to be passed into
releaseJdbcConnection
, ornull
if no JDBC Connection can be retrieved - Throws:
PersistenceException
- if thrown by JPA methodsSQLException
- if thrown by JDBC methods- See Also:
-