failed to lazily initialize a collection of role

List<Bdinfo> bdinfos= this.getByIds(Bdinfo.class,
bdinfoIds.toArray(new String[bdinfoIds.size()]));
for (Bdinfo bdinfo : bdinfos) {
   // 版本处理
   bizService.saveVer(bdinfo, xxxx, xxxx);
   // 删除Project表
   Project project = bdinfo.getPjid();
   if(project.getBdinfoCollection()==null && project.getBdintentCollection()==null){
   }
}

在saveVer方法中有调用:template.clear();

如此操作后调用该方法会提示:failed to lazily initialize a collection of role


修改为:
for (Bdinfo bdinfo : bdinfos) {
   // 版本处理
   bizService.saveVer(bdinfo, xxxx, xxxx);
   // 删除Project表
   //Project project = bdinfo.getPjid();
  Project project = getById(Project.class, bdinfo.getPjid().getId()); // 避免延迟加载的异常
   if(project.getBdinfoCollection()==null && project.getBdintentCollection()==null){
   }
}

猜你喜欢

转载自stonezsu.iteye.com/blog/1603662