Search in sources :

Example 6 with UnitOfWork

use of org.eclipse.persistence.sessions.UnitOfWork in project spring-framework by spring-projects.

the class EclipseLinkJpaDialect method beginTransaction.

@Override
@Nullable
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException {
    if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        // Pass custom isolation level on to EclipseLink's DatabaseLogin configuration
        // (since Spring 4.1.2)
        UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
        uow.getLogin().setTransactionIsolation(definition.getIsolationLevel());
    }
    entityManager.getTransaction().begin();
    if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) {
        // Begin an early transaction to force EclipseLink to get a JDBC Connection
        // so that Spring can manage transactions with JDBC as well as EclipseLink.
        entityManager.unwrap(UnitOfWork.class).beginEarlyTransaction();
    }
    return null;
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Nullable(org.springframework.lang.Nullable)

Aggregations

UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)6 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)1 Nullable (org.springframework.lang.Nullable)1