-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: session not closing in Hibernate3.0
PostPosted: Fri Jan 21, 2011 11:18 am 
Newbie

Joined: Fri Jan 21, 2011 10:36 am
Posts: 2
Hello Sirs/friends
I have a critical problem and struggling from last 15 days.My Go-live is on head.Please help me.

I am susing stuts,Hiberante3.0,SAP application server,Oracle database 9i.
In Hibernate 3.0 i am using Session.openSession() method and closing using session.close().When i check in v$session afetr some time session is abbrupty increasing and not releasing.After some time database got hanged.
I cant use session.getCurrentSession as it is available from 3.2.Now its risky to make it update from 3.0 to 3.2.
PLEASE HELP ME.

Hibernate.cfg.file
<property name="show_sql">true</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.c3p0.max_size">15</property>
<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.timeout">300</property>

DAO Class:
public List getEmployeeDetails(int employeeID) throws Exception {
String employeeName = null;
SessionFactory fact=null;
Session session = null;

System.out.println("Ist in DAO");
List empList=null;
try{
fact = InitSessionFactory.getSessionFactory();
session = fact.openSession();

Criteria criteria = session.createCriteria(employee_POJO.class);
System.out.println("Employee ID="+employeeID);
criteria.add(Expression.eq("employeeNo",new Integer(employeeID)));
empList = criteria.list();

System.out.println("Size="+empList.size());

for ( Iterator iter = empList.iterator(); iter.hasNext(); ) {
employee_POJO employee_POJO = (employee_POJO) iter.next();
employeeName = employee_POJO.getEmployeeName();
String area=employee_POJO.getArea();
System.out.println("Queried EmployeeName for C3p="+employeeName);
System.out.println("Queried area="+area);
System.out.println("Queried Supervisor="+employee_POJO.getSupervisorID());
}

//

}
catch(HibernateException err){
err.printStackTrace();

}finally{
session.flush();
session.close();


}
return empList;

}

InitSessionFactory class:
package com.claim.dao;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import org.hibernate.*;
import org.hibernate.cfg.*;


public class InitSessionFactory {

private static SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
System.out.println("entered the static try-catch block to read the configuration");
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
System.out.println("read the configuration file, created the session factory "+ sessionFactory);



} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.out.println("Initial SessionFactory creation failed1=" + ex.getMessage());
System.out.println("Initial SessionFactory creation failed2=" + ex.getLocalizedMessage());
System.out.println("Initial SessionFactory creation failed3=" + ex.getCause());
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}




}
PLEASE HELP ME.I am waiting
Thanks
Soumitra


Top
 Profile  
 
 Post subject: Re: session not closing in Hibernate3.0
PostPosted: Sat Jan 22, 2011 6:23 am 
Newbie

Joined: Fri Jan 21, 2011 10:36 am
Posts: 2
Please help Me.I am waiting


Top
 Profile  
 
 Post subject: Re: session not closing in Hibernate3.0
PostPosted: Sat Jan 22, 2011 10:45 am 
Newbie

Joined: Tue Jan 18, 2011 7:11 pm
Posts: 5
You have a potential problem in your 'finally' block: the flush() call can throw an exception and close() will not be called.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.