开发者

Hibernate Fails to Close Connection?

Is there any situation that hibernate fails to close the open connection???

I'm developing a JSF 2.0 application using Hibernate 3.2.5 and Oracle 10g express. After a fixed number of transactions, hibernate can not connect to the database anymore and even I can not connect using sqlDeveloper. As I inspected, the开发者_开发问答 number of transactions before this failure is almost equal to the number of processes in init.ora.

I always work with hibernate sessions like this:

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

My hibernate configuration

<?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>


There may be a problem related to your hibernate.connection.release_mode. Have a look at here .


I'd enable DEBUG for hibernate logging (specifically org.hibernate.transaction and org.hibernate.jdbc) and see what is going on. This way it is easier and as you are not using any pooling, this is the easiest way to find what's going on


In the .net world I check to see if session is not null and open before closing as sometimes I have seen this error, not sure if same goes for JPA but see code below...

e.g.

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

Also see this post

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜