我需要帮助
javax.persistence.PersistenceException: Hibernate cannot unwrap interface java.sql.Connection
我需要打开连接。这是为了从 glassfish 迁移到 JBoss eap 7。我不明白问题出在哪里。 JBoss不接受这个吗?还有其他方法可以展开吗?
我读了很多关于使用 Session
展开连接的文章,但是我的 IDE 显示 Session
not found。
我使用 JBoss eap 7 和 hibernate 2.1。
最佳答案
Jboss EAP7 支持 Hibernate 5.x,不支持 Hibernate 2.x。使用与特定 JBoss EAP 发行版捆绑在一起的 Hibernate 版本。
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
}
});
关于java - Hibernate 无法展开接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41705449/