JPA EntityManager获得session、connection

1、获得hibernate Session

Session session = entityManager.unwrap(org.hibernate.Session.class);

 

2、获得Java.sql.Connection

Session session = (org.hibernate.Session) em.getDelegate();

SessionFactoryImplementor sf = (SessionFactoryImplementor) session.getSessionFactory();

java.sql.Connection conn  = sf.getConnectionProvider().getConnection();

 

 

猜你喜欢

转载自1960370817.iteye.com/blog/2378204
JPA