Class EclipseLinkJpaDialect

java.lang.Object
org.springframework.orm.jpa.DefaultJpaDialect
org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect
All Implemented Interfaces:
Serializable, org.springframework.dao.support.PersistenceExceptionTranslator, JpaDialect

public class EclipseLinkJpaDialect extends DefaultJpaDialect
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 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, org.springframework.transaction.TransactionDefinition definition) throws PersistenceException, SQLException, org.springframework.transaction.TransactionException
      Description copied from class: DefaultJpaDialect
      This implementation invokes the standard JPA 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.

      Specified by:
      beginTransaction in interface JpaDialect
      Overrides:
      beginTransaction in class DefaultJpaDialect
      Parameters:
      entityManager - the EntityManager to begin a JPA transaction on
      definition - 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 the SavepointManager interface.
      Throws:
      PersistenceException - if thrown by JPA methods
      SQLException - if thrown by JDBC methods
      org.springframework.transaction.TransactionException - in case of invalid arguments
      See Also:
    • getJdbcConnection

      public org.springframework.jdbc.datasource.ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException
      Description copied from class: DefaultJpaDialect
      This implementation always returns null, indicating that no JDBC Connection can be provided.
      Specified by:
      getJdbcConnection in interface JpaDialect
      Overrides:
      getJdbcConnection in class DefaultJpaDialect
      Parameters:
      entityManager - the current JPA EntityManager
      readOnly - whether the Connection is only needed for read-only purposes
      Returns:
      a handle for the Connection, to be passed into releaseJdbcConnection, or null if no JDBC Connection can be retrieved
      Throws:
      PersistenceException - if thrown by JPA methods
      SQLException - if thrown by JDBC methods
      See Also: