Code:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() throws HibernateException {
return sessionFactory.openSession();
}
}
Code:
public ArrayList getRecents() {
try {
session = HibernateUtil.getSession();
this.videoList.clear();
Query med= session.createQuery("FROM Media m where m.fileName != :var1 ORDER BY m.id desc");
med.setString("var1", "");
session.flush();
session.close()
} catch (HibernateException ex) {
System.out.println("HibernateException populateRecentVideos : " + ex);
return null;
}
return med.list();;
}
In here if I use session.close(), I cant view list at jsp, I have to close session after rendering that list at page.
But It is too difficult to follow all codes in a full web application.
So, I want to close it as I posted in that method.
What is the wrong?