0

我有一个数据表,其中包含我的所有对象、制造商“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
4

1 回答 1

1

提交后关闭会话。

于 2013-04-15T16:29:10.563 回答