org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [org.model.Xsb#081101 ]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.model.Xsb#081101 ]
做个标记,出现此错误原因可能是因为数据库中的设置的字符长度大于在java中的长度。在比较相对应的内容是即无法相等,然后呢。看到网上资料说是去session重复创建,就本身的自己做的东西来讲是相同的内容重新放了一遍,所以才会报错。
public String selectKc() throws Exception { //1,从session中获得put的登录对象dlUser Map session=ActionContext.getContext().getSession(); Dlb dlUser=(Dlb) session.get("dlUser"); //2.利用dluser的用户名信息,去查询课程对象并讲该对象赋值给updatedKcs变量 ApplicationContext context=new FileSystemXmlApplicationContext("E:/Program Files/Workspaces/StudentLMW/src/applicationContext.xml"); XsDao xsDao=(XsDao) context.getBean("XsDaoImp"); Xsb xs=xsDao.getOneXs(dlUser.getXh()); Set existedKcs=xs.getKcs(); //迭代查询集合updateKcs中是否存在要选修的课程编号:selectActionKsb.getKch //存在,返回error,不存在将该项加入集合 Iterator iter=existedKcs.iterator(); while(iter.hasNext()){ Kcb kc=(Kcb) iter.next(); if(kc.getKch().equals(selectActionKcb.getKch())){ return "error"; } } KcDao kcDao=(KcDao) context.getBean("KcDaoImp"); Kcb selectedKc=kcDao.getOneKc(selectActionKcb.getKch()); //添加新选修的课程到已选课程的集合中 existedKcs.add(selectedKc); //设置更新后的课程集合updateedKcs xs.setKcs(existedKcs); xsDao.update(xs); return "success"; }