great_abe wrote:
Hi Again.. i am using a OpenSession to get a Session from my SessionFactory
is this the correct way to use it in a multi threading application
I don't think so. Please have a look at the reference doc :
http://www.hibernate.org/hib_docs/v3/re ... orial.html
You should prefer retrieving it this way :
Code:
HibernateUtil.getSessionFactory().getCurrentSession();
The HibernateUtil helper class is given in the reference documentation of Hibernate :
http://www.hibernate.org/hib_docs/v3/re ... pp-helpersCode:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Then, configure in hibernate.cfg.xml the thing I've spoken about before :
Code:
hibernate.current_session_context_class => thread
As explained in the doc, the meaning of the "current session" is depending on the configuration of this property "current_session_context_class". So give a special attention to it.
To finish, please don't forget to rate my answers by Yes or No it was useful below, as recalled in my signature. Thanks