I need help with
javax.persistence.PersistenceException: Hibernate cannot unwrap interface java.sql.Connection
I need to unwrap the connection. It's for a migration from glassfish to JBoss eap 7. I don't understand where the problem is. Does JBoss not accept this? Is there another way to do the unwrapping?
I read a lot about unwrapping the connection with Session
, but my IDE says Session
not found.
I work with JBoss eap 7 and hibernate 2.1.
Jboss EAP7 supports Hibernate 5.x, not Hibernate 2.x. Use the Hibernate version bundled with specific JBoss EAP release.
entityManager.getTransaction().begin();
java.sql.Connection connection = entityManager.unwrap(java.sql.Connection.class);
...
entityManager.getTransaction().commit();
Session hibernateSession = entityManager.unwrap(Session.class);
hibernateSession.doWork(new org.hibernate.jdbc.Work() {
@Override
public void execute(Connection connection) throws SQLException {
// do whatever you need to do with the connection
}
});
see here: http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With