Class EclipseLinkJpaDialect
- java.lang.Object
- org.springframework.orm.jpa.DefaultJpaDialect
- org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect
- All Implemented Interfaces:
Serializable
,PersistenceExceptionTranslator
,JpaDialect
public class EclipseLinkJpaDialect extends DefaultJpaDialect
JpaDialect
implementation for Eclipse Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.4.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.- Since:
- 2.5.2
- Author:
- Juergen Hoeller
- See Also:
setLazyDatabaseTransaction(boolean)
,LazyConnectionDataSourceProxy
, Serialized Form
Constructor Summary
Constructors Constructor Description EclipseLinkJpaDialect()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
beginTransaction(EntityManager entityManager, TransactionDefinition definition)
This implementation invokes the standard JPATransaction.begin
method.ConnectionHandle
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 Detail
EclipseLinkJpaDialect
public EclipseLinkJpaDialect()
Method Detail
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.
- See Also:
UnitOfWork.beginEarlyTransaction()
beginTransaction
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:
EntityTransaction.begin()
,InvalidIsolationLevelException
,DefaultJpaDialect.cleanupTransaction(java.lang.Object)
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:
JpaDialect.releaseJdbcConnection(org.springframework.jdbc.datasource.ConnectionHandle, javax.persistence.EntityManager)
,ConnectionHandle.getConnection()
,SimpleConnectionHandle
,JpaTransactionManager.setDataSource(javax.sql.DataSource)
,NativeJdbcExtractor