Q:

Hibernate session close already closed

I'm running a JSF application on Tomcat using Hibernate;
I have some dao methods to perform operations on the database, like this :
*
public boolean removeJprogram(Jobprogram jp) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        org.hibernate.Transaction tx = session.beginTransaction();
        try {
            session.delete(jp);
            tx.commit();
            System.out.println("Record deleted");
            return true;
        } catch (Exception e) {
            System.out.println(e.getMessage());
            tx.rollback();
            return false;
        }finally{
            session.close();
        }
    }

as I read in hibernate documentation; but i'have the error Session was already closed;
if i dont't put the session.close, sometimes give me the error session already opned or somtinh like this.

A:

Check the auto commit in hibernate configuration file, it might be set as true.

