我尝试删除时出现hibernate错误

时间:2013-04-15 16:25:12

标签: hibernate

我有一个包含所有对象的数据表,制造商列表“Fabricant”和两个按钮:更新和删除。

public class FabricantService {

private FabricantHome dao ;
Session sesion ;
List<Fabricant> list;

    public FabricantService() {
        super();
        dao = new FabricantHome();
    }



    public void ajouter(Fabricant cart) {

        sesion=HibernateUtil.getSessionFactory().getCurrentSession();
        sesion.beginTransaction();
        dao.persist(cart);
        sesion.getTransaction().commit();
              } 



    public void update(Fabricant cart) {
            sesion=HibernateUtil.getSessionFactory().getCurrentSession();
            sesion.beginTransaction();
            dao.merge(cart);
            sesion.getTransaction().commit();
    } 


   public void deletee (Fabricant cart) {
         sesion=HibernateUtil.getSessionFactory().getCurrentSession();
         sesion.beginTransaction();
         dao.delete(cart);
         sesion.getTransaction().commit();                      
}

public List<Fabricant> list(){
    sesion=HibernateUtil.getSessionFactory().getCurrentSession();
    sesion.beginTransaction();
    list=dao.findAll() ;
    return list;

    }


}

更新确定它可以在页面上重定向我以更新一个制造商。

但是当我选择删除此错误时会显示以下错误:

Caused by: javax.faces.el.EvaluationException: 
   org.hibernate.HibernateException: 
      Illegal attempt to associate a collection with two open sessions  
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)     
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    ... 23 more

1 个答案:

答案 0 :(得分:1)

提交后关闭会话。