failed to lazily initialize a collection of role 的问题
程序员文章站
2022-04-11 16:51:16
...
最近遇到这样的问题 failed to lazily initialize a collection of role
代码如下
//多对多定义
@ManyToMany
@JoinTable( name = "acct_user_group", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "group_id") })
//Fecth策略定义
@Fetch(FetchMode.SUBSELECT)
//集合按id排序.
@OrderBy("id")
//集合中对象id的缓存.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public List<Group> getGroupList() {
return groupList;
}
网上查了很多文章,都说是因为懒加载的问题。所以改成
//多对多定义
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable( name = "acct_user_group", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "group_id") })
//Fecth策略定义
@Fetch(FetchMode.SUBSELECT)
//集合按id排序.
@OrderBy("id")
//集合中对象id的缓存.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public List<Group> getGroupList() {
return groupList;
}
问题还是没有解决,最后吧@Fetch(FetchMode.SUBSELECT)注释掉就解决了问题
//多对多定义
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable( name = "acct_user_group", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "group_id") })
//Fecth策略定义
//@Fetch(FetchMode.SUBSELECT)
//集合按id排序.
@OrderBy("id")
//集合中对象id的缓存.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public List<Group> getGroupList() {
return groupList;
}
上一篇: Python—对字符编码的初步认识
下一篇: python的字符编码问题
推荐阅读
-
java 解决实体类序列化时,报failed to lazily initialize 的问题
-
解决问题:failed to lazily initialize a collection of role异常解决
-
JPA中failed to lazily initialize a collection of role:‘xxxx‘ no session or session was closed异常!
-
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