开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜