How to configure Sesion Factory in Hibernate to implement getCurrentSession
807580Oct 7 2009 — edited Oct 7 2009Hi,
I am new in Hibernate and I am using an application where I need to improve the performance while uploading the users through a utility. While analyzing the system, I found that, to insert a single user there were around 8 hits are made to DB to get the information and based on that finally it inserts the user. The strange thing I have noticed is that for every hit, a new DB connection is opened in code using the snippet getHibernateTemplate().getSessionFactory().openSession();
However, the connection is getting closed in finally block. But I think instead of using Open Connection; getCurrentSession can save time.
Can any one suggest whether I am on right track?
Also, when I have tried to use getCurrentSession I have simply replaced "getHibernateTemplate().getSessionFactory().openSession();" with "getHibernateTemplate().getSessionFactory().getCurrentSession();" from everywhere in code.
But when I tried to run the Utility I got some Hibernate Exception stating "No Hibernate Session bound to thread, and configuration does not allow creation".
Could anyone suggest do I need to configure anything else in my applicationcontext.xml to use the getCurrentSession() method.
Thanks in advance.