2

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>
DataNucleus
  • 15,497
  • 3
  • 32
  • 37
ehsun7b
  • 4,796
  • 14
  • 59
  • 98

3 Answers3

2

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

zinan.yumak
  • 1,590
  • 10
  • 9
2

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

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • Can you explain in more detail how to enable it? And by the way I'm using GlassFish application server, how can I configure a domain and get hibernate take connections from its pool? – ehsun7b Jan 03 '11 at 18:35
  • 1 thing at a time. First concentrate on determining why connections are not being closed. You need to go through the tutorial on how to enable the logging in slf4j. Hibernate uses it for logging so once you know how to configure the logging for slf4j then you are good. Read it here http://www.slf4j.org/manual.html Most of the time it is just placing a xml config file in the classpath. – Aravind Yarram Jan 03 '11 at 19:06
1

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

Community
  • 1
  • 1
Rippo
  • 22,117
  • 14
  • 78
  • 117
  • I have no problem when I call session.close(), but it seems that it does not close the underlying connection at all. – ehsun7b Jan 03 '11 at 13:57