private Connection createConnection ( ) { try { EntityTransaction tx = this . em . getTransaction ( ) ; if ( isHibernatePresentOnClasspath ( ) && em . getDelegate ( ) instanceof Session ) { connection = ( ( SessionImpl ) em . unwrap ( Session . class ) ) . connection ( ) ; } else { /** * see here:http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager */ tx . begin ( ) ; connection = em . unwrap ( Connection . class ) ; tx . commit ( ) ; } } catch ( Exception e ) { throw new RuntimeException ( "Could not create database connection" , e ) ; } return connection ; }
unfortunately there is no standard way to get jdbc connection from JPA entity manager