I m creating a DAO using Hibernate.
is it a good idea to create SessionFactory, Session and Transaction Objects as instance fields and initialize them in the Constructor?
should i close the session on every method that interact with the DB?
if not can you suggest a better design?
The transaction boundaries depend on how long your transactions are. Typically you manage one per request. In a Web-based app, you might start and end the transaction in a ServletFilter.
Thanks for your Help.
So you mean, get a new session instance from the sessionFactory and a new transaction from the session in every method and i dont need to close them untill i actually use the DAO in a servlet or so??