Session error in Java

1

I have the following methods:

public void delete(Class c, int id) throws SQLException {        
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    try{
        Object ob = this.getById(c, id);
        session.delete(ob);
        tx.commit();
        session.close();
    }catch(HibernateException e){
        tx.rollback();
        session.close();
        throw new SQLException(c.getName() + " - Não foi possivel excluir o registro!");
    }
}

public Object getById(Class c, Integer id) {
    Object session =  sessionFactory.getCurrentSession().get(c, id);
    return session;
}

But the following exception is returned: Illegal attempt to associate with collection with two open sessions

What should I do?

    
asked by anonymous 08.05.2015 / 21:02

0 answers