org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identi

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";
	}

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值