Spring managed transactions, EclipseLink JPA, custom isolation level Spring managed transactions, EclipseLink JPA, custom isolation level spring spring

Spring managed transactions, EclipseLink JPA, custom isolation level


I've given a try to this, but I am not completely sure of the solution. I've taken the code from this blog and adapted it for EclipseLink. Here's the code:

package com.byteslounge.spring.tx.dialect;import java.sql.SQLException;import javax.persistence.EntityManager;import javax.persistence.PersistenceException;import org.eclipse.persistence.sessions.UnitOfWork;import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect;import org.springframework.transaction.TransactionDefinition;import org.springframework.transaction.TransactionException;public class CustomEclipseLinkJpaDialect extends EclipseLinkJpaDialect {    private static final long serialVersionUID = 1L;    private boolean lazyDatabaseTransaction = false;    @Override    public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) {        this.lazyDatabaseTransaction = lazyDatabaseTransaction;    }    @Override    public Object beginTransaction(final EntityManager entityManager,            final TransactionDefinition definition)            throws PersistenceException, SQLException, TransactionException {        UnitOfWork uow = (UnitOfWork) getSession(entityManager);        uow.getLogin().setTransactionIsolation(definition.getIsolationLevel());        entityManager.getTransaction().begin();        if (!definition.isReadOnly() && !lazyDatabaseTransaction) {            uow.beginEarlyTransaction();        }        return null;    }}

I'm seeing the SERIALIZABLE isolation being logged when the transaction is initiated, but this needs to be tested properly to confirm it works.


Support for custom isolation level was added in Spring 4.1.2 to EclipseLinkJpaDialect


You can refer

"To achieve serializable transaction isolation with EclipseLink, we recommend that you use an isolated client session as follows:

Configure the database transaction isolation as serializable.Configure objects as isolated (see Configuring Cache Isolation at the Project Level or Configuring Cache Isolation at the Descriptor Level).Use the UnitOfWork method beginTransactionEarly (see Unit of Work Method beginTransactionEarly).If you are only concerned about the write aspect of serializable, optimistic locking is sufficient."

at http://docs.oracle.com/middleware/1212/toplink/OTLCG/cache.htm or go through http://docs.oracle.com/middleware/1212/toplink/OTLCG/cache.htmif any of isolation level meets your requirement