error:Found shared references to a collection:
2017-09-11 11:26
1231 查看
错误: Found shared references to a collection:
原因:BeanUtil.copyProperties()的方式复制一个实体bean,如果这个实体bean有一个集合属性,因为这个方法只是做了一个浅拷贝,所以新拷贝的实体跟旧的实体引用了同一个集合,而这个在hibernate中是不允许的,所以报错。
解决:在进行copyProperties拷贝后,新建一个集合,将原来的集合元素添加进去,并赋值给新拷贝的实体。
例:
BeanUtils.copyProperties(oldApplications, newApplications);
Set<ApplicationsUniv> appSet = oldApplications.getApplicationsunivs();
if(null!=appSet || !appSet.isEmpty()){
Set<ApplicationsUniv> newappSet = new HashSet<ApplicationsUniv>() ;
for(ApplicationsUniv appuniv : appSet){
newappSet.add(appuniv);
}
newApplications.setApplicationsunivs(newappSet);
}
原因:BeanUtil.copyProperties()的方式复制一个实体bean,如果这个实体bean有一个集合属性,因为这个方法只是做了一个浅拷贝,所以新拷贝的实体跟旧的实体引用了同一个集合,而这个在hibernate中是不允许的,所以报错。
解决:在进行copyProperties拷贝后,新建一个集合,将原来的集合元素添加进去,并赋值给新拷贝的实体。
例:
BeanUtils.copyProperties(oldApplications, newApplications);
Set<ApplicationsUniv> appSet = oldApplications.getApplicationsunivs();
if(null!=appSet || !appSet.isEmpty()){
Set<ApplicationsUniv> newappSet = new HashSet<ApplicationsUniv>() ;
for(ApplicationsUniv appuniv : appSet){
newappSet.add(appuniv);
}
newApplications.setApplicationsunivs(newappSet);
}
相关文章推荐
- 使用hibernate,在面对复杂业务处理的时候,你是否很顺手,由Exception-found shared references to a collection说开去
- hibernate异常"Found shared references to a collection
- hibernate异常"Found shared references to a collection"
- hibernate异常"Found shared references to a collection 解决方法
- hibernate异常"Found shared references to a collection"
- hibernate异常"Found shared references to a collection
- Found shared references to a collection: com.morepower.domain.oa.TreeNode.permissions
- Found shared references to a collection
- Hibernate JPA —— could not insert 或 detach entity passed to persist 或Found shared references 错误
- RSC-010, ERROR, [Reference to non-standard resource type found.]
- [BUG]error: reference to ‘shared_ptr’ is ambiguous
- win7下qt error: undefined reference to `_imp__getnameinfo@28'解决
- iOS ERROR ITMS-90032 : "Invalid Image Path - No image found at the path referenced under key
- Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. T
- 20100507 学习记录: Server Error in '/' Application. Object reference not set to an instance of an object
- cocos2d打包安卓.so时候,error: undefined reference to!
- register.o: undefined reference to symbol 'gpg_strerror'编译错误的解法
- 解决Xcode上传出现的Error ITMS-9000问题 ,No image found at the path referenced under key CFBundleIcons AppIcon
- crtbegin_dynamic.o: in function _start:crtbrand.c(.text+0x78): error: undefined reference to 'main
- 安装imaconfigure: error: not found. Please provide a path to MagickWand-config or Wand-config program.