Top Description Inners Fields Constructors Methods
org.springframework.orm.jpa.vendor

public Class EclipseLinkJpaDialect

extends DefaultJpaDialect
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.sql.Connection, .SQLException, jakarta.persistence.EntityManager, .PersistenceException, org.eclipse.persistence.sessions.DatabaseLogin, .UnitOfWork, org.springframework.jdbc.datasource.ConnectionHandle, org.springframework.lang.Nullable, org.springframework.orm.jpa.DefaultJpaDialect, org.springframework.transaction.TransactionDefinition, .TransactionException

org.springframework.orm.jpa.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.

Author
Juergen Hoeller
Since
2.5.2
See Also
setLazyDatabaseTransaction, org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
EclipseLinkJpaDialect.EclipseLinkConnectionHandle

ConnectionHandle implementation that lazily fetches an EclipseLink-provided Connection on the first getConnection call - which may never come if no application code requests a JDBC Connection.

Field Summary

Modifier and TypeField and Description
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
beginTransaction(EntityManager
the EntityManager to begin a JPA transaction on
entityManager
,
TransactionDefinition
the Spring transaction definition that defines semantics
definition
)

Overrides org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction.

Implements org.springframework.orm.jpa.JpaDialect.beginTransaction.

This implementation invokes the standard JPA Transaction.begin method.

public ConnectionHandle
getJdbcConnection(EntityManager
the current JPA EntityManager
entityManager
,
boolean
whether the Connection is only needed for read-only purposes
readOnly
)

Overrides org.springframework.orm.jpa.DefaultJpaDialect.getJdbcConnection.

Implements org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

This implementation always returns null, indicating that no JDBC Connection can be provided.

public void
setLazyDatabaseTransaction(boolean lazyDatabaseTransaction)

Set whether to lazily start a database resource transaction within a Spring-managed EclipseLink transaction.

Inherited from org.springframework.orm.jpa.DefaultJpaDialect:
cleanupTransactionprepareTransactionreleaseJdbcConnectiontranslateExceptionIfPossible

Field Detail

lazyDatabaseTransactionback to summary
private boolean lazyDatabaseTransaction

Constructor Detail

EclipseLinkJpaDialectback to summary
public EclipseLinkJpaDialect()

Method Detail

beginTransactionback to summary
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException

Overrides org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction.

Implements org.springframework.orm.jpa.JpaDialect.beginTransaction.

Doc from org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction.

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.

Parameters
entityManager:EntityManager

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

the EntityManager to begin a JPA transaction on

definition:TransactionDefinition

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

the Spring transaction definition that defines semantics

Returns:Object

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction). May implement the org.springframework.transaction.SavepointManager interface.

Annotations
@Override
@Nullable
Exceptions
PersistenceException:

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

if thrown by JPA methods

SQLException:

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

if thrown by JDBC methods

TransactionException:

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

in case of invalid arguments

getJdbcConnectionback to summary
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException

Overrides org.springframework.orm.jpa.DefaultJpaDialect.getJdbcConnection.

Implements org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

Doc from org.springframework.orm.jpa.DefaultJpaDialect.getJdbcConnection.

This implementation always returns null, indicating that no JDBC Connection can be provided.

Parameters
entityManager:EntityManager

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

the current JPA EntityManager

readOnly:boolean

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

whether the Connection is only needed for read-only purposes

Returns:ConnectionHandle

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

a handle for the Connection, to be passed into releaseJdbcConnection, or null if no JDBC Connection can be retrieved

Annotations
@Override
Exceptions
PersistenceException:

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

if thrown by JPA methods

SQLException:

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

if thrown by JDBC methods

setLazyDatabaseTransactionback to summary
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
org.eclipse.persistence.sessions.UnitOfWork#beginEarlyTransaction(), TransactionDefinition#isReadOnly(), TransactionDefinition#getIsolationLevel()
org.springframework.orm.jpa.vendor back to summary

private Class EclipseLinkJpaDialect.EclipseLinkConnectionHandle

extends Object
implements ConnectionHandle
Class Inheritance
  • java.lang.Object
  • org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect.EclipseLinkConnectionHandle
All Implemented Interfaces
org.springframework.jdbc.datasource.ConnectionHandle

ConnectionHandle implementation that lazily fetches an EclipseLink-provided Connection on the first getConnection call - which may never come if no application code requests a JDBC Connection. This is useful to defer the early transaction begin that obtaining a JDBC Connection implies within an EclipseLink EntityManager.

Field Summary

Modifier and TypeField and Description
private Connection
private final EntityManager

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Connection
getConnection()

Implements org.springframework.jdbc.datasource.ConnectionHandle.getConnection.

Fetch the JDBC Connection that this handle refers to.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
private Connection connection
Annotations
@Nullable
entityManagerback to summary
private final EntityManager entityManager

Constructor Detail

EclipseLinkConnectionHandleback to summary
public EclipseLinkConnectionHandle(EntityManager entityManager)

Method Detail

getConnectionback to summary
public Connection getConnection()

Implements org.springframework.jdbc.datasource.ConnectionHandle.getConnection.

Doc from org.springframework.jdbc.datasource.ConnectionHandle.getConnection.

Fetch the JDBC Connection that this handle refers to.

Annotations
@Override