Hi everybody,
I'm new to hibernate. I'm developping a web application with apache tomcat 6 and I'm not sure about the best way to handle the database transactions in my application. Currently I'm opening a session and begin a transaction when I start processing a request and i'm closing the session when processing is finished.
Code:
Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
[...]
session.close();
All my classes in the application access the current session like this
Code:
Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
session.get( ... );
[...]
Are there any best practices to handle transactions in web applications? Is it recommmendable to use openejb (and the annotations @TransactionAttribute) to handle the transactions?
Thanks in advance!