Quote:
If there are multiple DAO calls in a single request then session.getCurrentSession() is useful.
Yes that is correct.
Quote:
But if there is only single DAO call per request then session.openSession() is the right way.
Yes and no. But mainly no. Typically, you shouldn't open and close sessions in your DAO classes because they don't know if other DAOs are going to need the same sessions. The best thing to do is open a session for each incoming request (using a filter is the easiest way to do this) and then calling sessionFactory.getCurrentSession() in all your DAOs to get the current session. That way all your DAOs will be easily reusable.
This is the open-session-in-view pattern and is definitely the way forward here. You can find documentation at
http://www.hibernate.org/43.html. Opening a session is a very cheap operation (and doesn't necessarily need to obtain a database connection) so opening a session for each incoming request is a minimal performance hit.
Neil