我的项目是基于SSH框架的
有A表,B表
A表的Id自增
B表的Id引用A表的Id
当我要修改B表的时候必须同时修改A表
最后保存的时候报错:
org.springframework.orm.hibernate3.HibernateSystemException:
a different object with the same identifier value was already associated with the session: Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
有A表,B表
A表的Id自增
B表的Id引用A表的Id
当我要修改B表的时候必须同时修改A表
最后保存的时候报错:
org.springframework.orm.hibernate3.HibernateSystemException:
a different object with the same identifier value was already associated with the session: Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
试试这个
web.xml里面配置<filter>
<filter-name>openSession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSession</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
但是报:
同一个session里面有了两个相同标识但是是不同实体
属性名称 字段名称
设备标识 DeviceId
设备分类 DeviceClass
设备名称 DeviceName
上线日期 UplineDate
购买日期 BuyDate
设备描述 Description
删除标志 DelFlag表名 Net_OtherDeviceInfo
属性名称 字段名称
设备标识 DeviceId
设备分类 DeviceClass
设备类别 DeviceType
归属厂家 Factory
设备名称 DeviceName
管理IP地址 IpAddress
机箱序列号 ChassisSerial
设备版本 DeviceVersion
型号标识 ModelId
操作用户 UserId
采集状态 Status
设备描述 SysDescr
log.debug("保存设备基本信息成功");
netRoutinfo.setRoutId(netDeviceinfo.getDeviceId());
netRoutinfo.setManager(UserId);
super.save(netRoutinfo);当我保存了netDeviceinfo表之后就保存netRoutinfo表
问题解决了
是由于我在更改设备的时候重新new了一个实体对象
系统就认为我是插入不是更改 所有保存
解决方法:
判断一下 如果是更改设备内容先到数据库中获得对象
然后再进行修改