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();

 

 

你可能感兴趣的:(JPA EntityManager??session?connection)