Hi everyone
I'm using hibernate with eclipse helios to extract data from a MySQL database. I have done several querys with the same format, but when I do a specific query Hibernate throws a Hibernate exception and with System.out.println(e.getMessage()); I get this: Session is closed!
I have checked before doing the query if the session is open (System.out.println(HibernateUtil.getSessionFactory().getCurrentSession().isOpen());) and it seems to be ok... The exception is thrown when i do the query. This is the first time in the code i'm opening a session btw.
here is the code:
Quote:
{
Transaction tx=null;
try{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
tx=session.beginTransaction();
System.out.println(HibernateUtil.getSessionFactory().getCurrentSession().isOpen());
Query q = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("SELECT r.name, count(log.time) as numeroClicks FROM MdlResource r ,MdlCourseModules cm ,MdlModules modu, MdlLog log WHERE modu.name = 'resource' AND cm.instance=r.id AND modu.id=cm.module AND cm.id=log.cmid AND cmid!=0 GROUP BY r.name ORDER BY r.name");
if(q.list().size()!=0){
tx.commit();
return q.list();
}
else{
tx.commit();
return null;
}
}catch(HibernateException e){
System.out.println(e.getMessage());
e.getStackTrace();
return null;
}
Thanks for helping :D