EclipseLink: Checking current transaction isolation level
I ha开发者_开发知识库ve 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!
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
- Getting a JDBC Connection from an EntityManager (covers both JPA 1.0 and JPA 2.0)
精彩评论