I would like to set isolation level using eclipse link,
I tried these 2 ways to do it:
java.sql.Connection
mgr = EMF.get().createEntityManager(); tx = mgr.getTransaction(); tx.begin(); java.sql.Connection connection = mgr.unwrap(java.sql.Connection.class); connection.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); System.out.println("Connection: "+connection.getTransactionIsolation()); //prints TRANSACTION_READ_COMMITED as expected org.eclipse.persistence.sessions.DatabaseLogin databaseLogin = new DatabaseLogin(); System.out.println("DatabaseLoging: "+databaseLogin.getTransactionIsolation()); //prints -1, representing transaction isolation is not set
DatabaseLogin setTransationIsolation method
mgr = EMF.get().createEntityManager(); tx = mgr.getTransaction(); tx.begin(); org.eclipse.persistence.sessions.DatabaseLogin databaseLogin = new DatabaseLogin(); databaseLogin.setTransactionIsolation(DatabaseLogin.TRANSACTION_READ_COMMITTED); System.out.println("DatabaseLoging: "+databaseLogin.getTransactionIsolation()); //prints TRANSACTION_READ_COMMITED as expected java.sql.Connection connection = mgr.unwrap(java.sql.Connection.class); System.out.println("Connection: "+connection.getTransactionIsolation()); //prints TRANSACTION_REPEATABLE_READ
As you can see there are some inconsistencies between the return values of getTransacationIsolation() method. My question is, which transaction isolation is really set in both cases ? I know that eclipse link uses different connection for read and write operations by default, DatabaseLogin.setTransactionIsolation should set the isolation level for both connections, so why Connection.getTransactionIsolation still returns another isolation level ?
I am using Application scoped EntityManager, JPA 2.0, EclipseLink 2.5.2.
If there are more preferable ways setting the transaction isolation, please let me know.