Close session connection in Hibernate

This is my Hibernate criteria query:

Criteria criteria = sessionFactory.getCurrentSession().createCriteria(myclass.class, "b");
ProjectionList properties = Projections.projectionList();
listArr = criteria.setResultTransformer(Transformers.aliasToBean(HashMap.class)).list();

I want to close session connection after executing query.

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

You are use sessionFactory.getCurrentSession(), So you no need to flush and close session. it automatically flush and close when transaction end. more getCurrentSession When you call SessionFactory. getCurrentSession, it will provide you session object which is in hibernate context and managed by hibernate internally. It is bound to transaction scope. When you call SessionFactory. getCurrentSession , it creates a new Session if not exists , else use same session which is in current hibernate context. openSession When you call SessionFactory.openSession, it always create new Session object afresh and give it to you. You need to explicitly flush and close these… Read more »