[#0x0048] hibernate延迟加载的错误

  异常信息:failed to lazily initialize a collection of role: <容器类对象>, no session or session was closed

 

  这个问题一般出现在@OneToMany的情况下,解决的方法:
1. 如果是xml配置,在hbm文件中的对应属性上配置lazy=“false”
2. 如果是用annotation,则配置如下
@OneToMany(
  targetEntity = CourseAuthorizationItem.class,
  cascade = { CascadeType.PERSIST, CascadeType.MERGE },
  mappedBy = "xxx", fetch = FetchType.EAGER
)
将fetch类型设置成直接获取

你可能感兴趣的:(Hibernate,xml)