日期:2014-05-19  浏览次数:20731 次

求助:hibernate持久化问题identifier of an instance of
[size=16px][size=12px]异常信息如下:
org.springframework.orm.hibernate3.HibernateSystemException: identifier of an instance of com.strongit.guard.bo.GrdDict was altered from 1112 to 1113; nested exception is org.hibernate.HibernateException: identifier of an instance of com.strongit.guard.bo.GrdDict was altered from 1112 to 1113

页面代码:
<s:select id="gunType" list="grdDictList"  listKey="dictId" listValue="content" 
headerKey="" headerValue="请选择枪械类型" name="guns.grdDict.dictId" cssStyle="width:222px;"></s:select>

Action层:
String dictId=guns.getGrdDict().getDictId();
try {
this.iGunsService.updateGun(guns, dictId);

} catch (Exception e) {
e.printStackTrace();
}
Service层:
//修改操作
public void updateGun(Guns gun,String dictId) {
GrdDict gDict=new GrdDict();
                  gun.setGrdDict(iGrdDictService.getDictById(dictId));
gun.setGrdDict(gDict);
this.gunDao.save(gun);
}
实体类:
1.Guns枪械信息
private GrdDict grdDict;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="GUN_TYPE")
public GrdDict getGrdDict() {
return grdDict;
}
public void setGrdDict(GrdDict grdDict) {
this.grdDict = grdDict;
}
2.数据字典GrdDict实体:
private String dictId; //字典编码
private String dictType; //字典类型
private String content; /字典内容
private String remark; //备注

解释如下:
GrdDict为数据字典,保存了枪械类型(字典编码为枪械类型Id,字典类型:gunType,字典内容:枪械类型名称),当在页面中修改枪械类型时,就会报上面的异常。我觉得原因是hibernate不允许修改持久化对象。在网上也找了很多,但都不是我的答案,现求助csdn的各位大侠,望知道或遇到过类似情况的同事帮助小弟!

------解决方案--------------------
不能修改持久化对象的主键!!!!
------解决方案--------------------
http://keliang-liu.iteye.com/blog/91885