Question

I have a standalone Java application that uses EclipseLink 2.0.1. It is configured by a persistence.xml, and then does something like:

final EntityManagerFactory emf = Persistence.createEntityManagerFactory("xy");
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
....
em.getTransaction().commit();

I want to find out, which Database Transaction Isolation level actually applies to that transaction. Even a "dirty debugging only" solution would be helpful.

The EclipseLink documentation describes, that

Achieving a particular database transaction isolation level in an EclipseLink application is more involved than simply using the DatabaseLogin method setTransactionIsolation

so I want to make sure, that my desired isolation level applies!

Was it helpful?

Solution

Using Connection#getTransactionLevel() on the underlying Connection should work. Here is how you can get it with JPA 2.0:

final EntityManagerFactory emf = Persistence.createEntityManagerFactory("xy");
final EntityManager em = emf.createEntityManager();
em.getTransaction().begin();

java.sql.Connection connection = em.unwrap(java.sql.Connection.class);
System.out.println(connection.getTransactionIsolation());

....
em.getTransaction().commit();

Reference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top