Hibernate:LazyInitializationException: failed to lazily initialize a collection of rol
程序员文章站
2022-03-02 13:25:12
...
Hibernate日常异常:关系映射查询懒加载
在进行一对多的查询中(shop有多个order),遇到了failed to lazily initialize a collection of rol错误。很明显,这里是查询的时候由于懒加载的原因session关闭了,于是接着shop表往下查order的时候失去了session。
这里我们采用配置文件设置懒加载的方式:
一对多:
<set name="orders" cascade="save-update,delete" lazy="false">
<key column="shopId"/><!--Order表中记录的shopId-->
<one-to-many class="entity.Order"/>
</set>
多对一:默认懒加载即可
<many-to-one name="shop" column="shopId" class="entity.Shop" not-null="true"/>
hibernate注解设置懒加载: 传送门
上一篇: 音视频数据库 GRID 爬取
下一篇: VUE—简单认识
推荐阅读
-
解决问题:failed to lazily initialize a collection of role异常解决
-
JPA中failed to lazily initialize a collection of role:‘xxxx‘ no session or session was closed异常!
-
org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily i
-
OneToMany字段序列化 failed to lazily initialize a collection of role
-
failed to lazily initialize a collection of role: , could not initialize proxy - no Session
-
Hibernate 延迟加载的错误 failed to lazily initialize a collection of role
-
failed to lazily initialize a collection of role
-
failed to lazily initialize a collection of role 异常
-
failed to lazily initialize a collection of role 的问题
-
SSH项目,failed to lazily initialize a collection of role