on Hibernate 2.1.2 (and MySQL 4.1.x):
Hi folks.
I want to confirm correspondence of pool size and the number of database connections.
How can I confirm about Hibernate uses appropriately the connection-pooling set up by 'hibernate.connection.pool_size'?
I coded :
Code:
public class TestHibernateSession {
private SessionFactory sessionFactory = null;
private ThreadLocal session = null;
public static void main(String[] args) throws HibernateException {
new TestHibernateSession();
}
public TestHibernateSession() throws HibernateException {
sessionFactory = new Configuration().configure().buildSessionFactory();
session = new ThreadLocal();
Session sess1 = (Session)session.get();
if(sess1 == null){
sess1 = sessionFactory.openSession();
session.set(sess1);
}
Session sess2 = (Session)session.get();
if(sess2 == null){
sess2 = sessionFactory.openSession();
session.set(sess2);
}
Session sess3 = (Session)session.get();
if(sess3 == null){
sess3 = sessionFactory.openSession();
session.set(sess3);
}
System.out.println( "sess1 : " + System.identityHashCode(sess1.connection()));
System.out.println( "sess2 : " + System.identityHashCode(sess2.connection()));
System.out.println( "sess3 : " + System.identityHashCode(sess3.connection()));
sess1.close();
sess2.close();
sess3.close();
sessionFactory.close();
}
}
and, setup in hibernate.cfg.xml:
<property name="hibernate.connection.pool_size">2</property>
'hibernate.properties' is not available.
I get message in console when program running:
>sess1 : 19147537
>sess2 : 19147537
>sess3 : 19147537
I expect the result of using 'System.identityHashCode()' from which each differs.
or, is this means a mistake primarily?
best regards,
Thanks.