
Hello.
I'm developing a web application using Struts 1.0 and Hibernate (I'm a beginner). I've been reading your web and I've seen that in the Struts Action methods you use an Hibernate Plugin in this way:
public ActionForward myMethod (.......){
ServletContext context = request.getSession().getServletContext();
SessionFactory _factory = (SessionFactory);
context.getAttribute(HibernatePlugIn.SESSIONFACTORYKEY);
Session session = _factory.openSession();
Transaction tx = session.beginTransaction();
//... do session stuff
tx.commit();
session.flush();
session.close();
...
What is the difference between doing this and this other?
public ActionForward myMethod (.......){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
//... do session stuff
tx.commit();
.....
Some questions: 1.- What is the best option? 2.- I've read that it's not necessary to close Hibernate session nor flush the session if you use .getCurrentSession(). Is it true?
Thanks in advance.