FetchType.LAZY 时属性加上@JsonIgnore,避免返回时报错:Could not write JSON: failed to lazily initialize a collection of role


【示例】

@OneToMany(fetch=FetchType.LAZY)
@JsonIgnore
@Fetch(FetchMode.SELECT)
@Cascade(value={CascadeType.SAVE_UPDATE})
@JoinColumn(name="userId",updatable=false)
private Set<UserRoleBean> userRoleSet = new HashSet<UserRoleBean>();

----------------------------------------------------------------------------------------------

【说明】

json序列化时将java bean中的一些属性忽略掉,序列化和反序列化都受影响

上述代码userRoleSet 属性上加了  @JsonIgnore,这个时候从后台推数据到前台的时候,就会把userRoleSet 这个引用属性给忽略掉。

避免返回写json时报错:

HTTP Status 500 - Could not write JSON: failed to lazily initialize a collection of role: 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM