first, sorry for my poor english^^;
I am building multi threaded java applications without web server.
some configuration properties of my hibernate.cfg.xml are like this.
Code:
...
...
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
...
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.max_fetch_depth">1</property>
<property name="hibernate.show_sql">true</property>
one of my app, I run 5 thread(same java class) concurrently and they get their work repeatedly from one shared queue.
But, I doubt this is right coding...
I will show you seudo code..
Code:
try{
sess = HibernateUtil.getSessionFactory()getCurrentSession();
tx = sess.beginTransaction();
objList = sess.createQuery(.......).list();
...
...
new SomeNonThreadClass(objList.get(0),...).callSomeMethod();
...
tx.commit();
} catch(HibernateException e){
if( tx != null) tx.rollback();
....
}
HibernateUtil use singleton pattern for session factory.
In code above, SomeNonThreadClass is plain pojo didn't extends Thread feature.
And SomeNonThreadClass is using HibernateUtil and Session.
My question is..
1) Is it problem using getCurrentSession method in SomeNonThreadClass.
2) I using now OpenSession and session.close in SomeNonThreadClass. Is it more right for this case?
3) singletoned HibernateUtil is right usage in multi thread env?
I will appreciate all your advice.
Thanks in advance^^