修改学生信息后如何关闭session 下面的代码确切的说还是会报错
//修改学生资料动作
public String modify()
{
//获取传递过来的学生编号
System.out.println("修改方法");
String teacherid = request.getParameter("teacherid");
System.out.println("teacherid"+teacherid);
TeacherDAO sdao = new TeacherDAOImpl();
Teacher s=sdao.queryTeacherByTeacherid(teacherid);
System.out.println("user"+s.toString());
//保存在会话中
session.setAttribute("s", s);
//request.setAttribute("s", s);
request.setAttribute("teacherid", teacherid);
return "modify_success";
}
//保存修改后的学生资料动作
public String save() throws Exception
{
System.out.println("修改保存。。。");
Teacher s=new Teacher();
s.setTeacherID(request.getParameter("student2.teacherID"));
s.setPassword(request.getParameter("student2.password"));
TeacherDAO sdao=new TeacherDAOImpl();
sdao.updateTeacher(s);
session.invalidate();
return "savel_success";
}
========================================================
报错:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.sanqing.po.Teacher#t0000012]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:590)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:284)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:223)
at org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireUpdate(SessionImpl.java:565)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:553)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:545)
at com.sanqing.dao.TeacherDAOImpl.updateTeacher(TeacherDAOImpl.java:96)
at com.sanqing.action.TeacherAction.save(TeacherAction.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)