views:

99

answers:

1

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!

+2  A: 

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

Pascal Thivent
Perfect answer! (I still had javax.persistence.1.0.x on my classpath for my test project, so I didn't see the unwrap method at all. Wouldn't have found it without your help. Thanks!)
Chris Lercher
@chris You're welcome.
Pascal Thivent
Thanks also for the update - good to know, how to do it in JPA 1.0, too.
Chris Lercher
Yeah, especially since it's provider specific in JPA 1.0.
Pascal Thivent