我有一个包含所有对象的数据表,制造商列表“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
答案 0 :(得分:1)
提交后关闭会话。