vendredi 8 mai 2015

Session error in Java

I have this method :

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!");
    }
}

and this other:

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

This exception is returned : Illegal attempt to associate a collection with two open sessions

What is my error ?




Aucun commentaire:

Enregistrer un commentaire