Hi All,
I'm developing a web application with Oracle 10.2 and I'm having a problem regarding the continue growing up of sessions on database.
I configure hibernate with c3p0 as follow:
Code:
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.idle_test_period">70</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">40</property>
<property name="hibernate.c3p0.timeout">180</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.generate_statistics">false</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.connection.SetBigStringTryClob">true</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.dbcp.ps.maxIdle">0</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
What I cannot understand is why on my database there are more than the configured maximum 40 sessions.
Reading the documentation I'm expecting that configuring the property hibernate.c3p0.max_size to 40, that's the maximum number of sessions I have to found in my Oracle application database.
Java code is the following:
Code:
/* This is the class that instantiate the session factory */
public class HibernateUtil {
private static SessionFactory sessionFactory;
// this method is called once in the web application startup
public static void init() throws Exception{
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
}
catch (Exception ex) {}
}
}
public static SessionFactory getSessionFactory() throws Exception {
return sessionFactory;
}
}
For each SQL statement (select, update, insert) I use the following schema:
Code:
public void myMethodSql()
{
ResultSet rset=null;
PreparedStatement ps=null;
try{
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
String mySQLStatement = "SELECT * FROM ....";
ps = HibernateUtil.getSessionFactory().getCurrentSession().connection().prepareStatement(mySQLStatement);
rset = ps.executeQuery();
// ...parse Result Set ...
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
}
catch(Exception e) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
} catch (Exception e1) {}
}
finally {
if (rset!=null) {
try {
rset.close();
} catch (SQLException e) {}
}
if (ps!=null) {
try {
ps.close();
} catch (SQLException e) {}
}
}
}
Should I have to close session after commit/rollback using:
Code:
HibernateUtil.getSessionFactory().getCurrentSession().close();
I'm not using (and I don't want use) hibernate sql language. Also I don't (want to) map all database tables.
Thanks.