java - Hibernate 无法展开接口(interface)

标签 java hibernate jboss

我需要帮助

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

请看这里:http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager

关于java - Hibernate 无法展开接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41705449/

相关文章:

hibernate - org.hibernate.MappingException : Unable to find column with logical name

jboss - 此处不允许使用 Wildfly 子系统配置属性

java - KeycloakWebSecurityConfigurerAdapter 与 JBoss stadalon.xml

java - 如何按值对 TreeSet 进行排序?

java - 如何在 Hibernate Spring 中级联 CollectionElement

css - 使用 JBoss jDocBook maven 插件自定义 CSS

java - org.jboss.weld.exceptions.DeploymentException WELD-001409 : Ambiguous dependencies for type X with qualifiers @Default

java - 为什么我的最终 JOptionPane 消息没有显示?

java - Spring Controller 中的自定义注解绑定(bind)

java - 适用于 JSF、Java 和 hibernate 框架的良好代码审查工具