Hibernate无法关闭连接?

时间:2011-01-03 13:19:59

标签: hibernate jsf-2

是否存在 hibernate 无法关闭打开的连接 ???

的情况

我正在使用 Hibernate 3.2.5 Oracle 10g express 开发 JSF 2.0 应用程序。经过一定数量的事务后,hibernate可以再连接到数据库,甚至无法使用 sqlDeveloper 进行连接。在我检查过的情况下,此次失败前的交易次数几乎等于 init.ora 进程 的数量>

我总是使用像这样的hibernate会话:

try {
      session.beginTransaction();

      ... 

    } catch (Exception ex) {
      Transaction tx = session.getTransaction();
      if (tx.isActive()) {
        tx.rollback();
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, ex.getMessage(), ex.getMessage()));
      }
    } finally {
      session.close();
    }

我的休眠配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
    <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
    <property name="hibernate.connection.username">CUSTOMS_G2G</property>
    <property name="hibernate.connection.password">123456</property>
    <mapping resource="ir/khorasancustoms/g2g/persistance/UserGroup.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/User.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/CatalogGroup.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/CatalogValue.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/gates/Receipt.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/gates/Price.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/gates/Promise.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/gates/Exit.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/gates/Weight.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/gates/Fee.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/Page.hbm.xml"/>
    <mapping resource="ir/khorasancustoms/g2g/persistance/Permission.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

3 个答案:

答案 0 :(得分:2)

您的hibernate.connection.release_mode可能存在问题。看看here

答案 1 :(得分:2)

我为hibernate logging启用了DEBUG(特别是 org.hibernate.transaction org.hibernate.jdbc ),看看发生了什么。这种方式更容易,因为您没有使用任何池,这是查找正在发生的事情的最简单方法

答案 2 :(得分:1)

在.net世界中,我在关闭之前检查会话是not null还是open,因为有时我看到了这个错误,不确定JPA是否一样,但请看下面的代码......

e.g。

if (session != null && session.IsOpen)
      session.close();

另见post