OneToMany字段序列化 failed to lazily initialize a collection of role
程序员文章站
2022-04-11 17:21:31
...
hibernate项目中,如果要对onetomany的pojo对象中的字段序列化,则会抛
failed to lazily initialize a collection of role错误。
解决方法1:
目前我是用Jackson中的@JsonIgnore来处理,然后还是用jackson来序列化或输出。
我一般不用jackson来做序列化输出,习惯用struts2自带的。
@jsonIgnore写在get上,写在属性上无作用。
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "controller")
@JsonIgnore
public Set<Alarm> getAlarms() {
return this.alarms;
}
解决方法2:
还是用struts2的json输出
hibernate实体改为:
@JSON(serialize=false)
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "userinfo")
public List<UserGroup> getUserGroups() {
return this.userGroups;
}
推荐阅读
-
解决问题: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
-
failed to lazily initialize a collection of role问题