修改学生信息结束后如何关闭session
发表在JavaWeb图书答疑 2017-11-09 悬赏:10 学分 《Java Web程序设计 慕课版》第13章 Spring与Struts2、Hibernate框架的整合
是否精华
版块置顶:

修改学生信息后如何关闭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)


分享到:
精彩评论 1
无语_mrkj
学分:3155 LV11
2017-11-10
沙发

请问这个段代码是哪个实例中的,我没有找呢?

首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照