I have an application, and in the DAO layer where the database transactions occur I have the following sample code:
Code:
public User getUser() {
Session session = HibernateUtil.getCurrentSession();
Transaction tx = session.beginTransaction();
......
tx.close();
session.close();
}
1)I want to ask if
I must close session in every DAO method as I am doing above?Or I should never close it?
2)Is
session.flush() necessary;
3)When I get session -->
HibernateUtil.getCurrentSession();
if there is existing session, Hibernate will not create a new one right?If there is no session, Hibernate will create a new one?
Thanking you in advance...