jpa實(shí)體@ManyToOne @OneToMany無(wú)限遞歸
問(wèn)題描述
Cannot call sendError() after the response has been committed
解決辦法
在屬性上添加注釋
1
2
3
4
|
@JsonBackReference // data to json 和 JsonIgnore一樣 // @JsonManagedReference // data to json 會(huì)被序列化 // @JsonIgnore // 直接忽略子實(shí)體 private Collection<ArticleEntity> articlesById; |
-
@JsonIgnore
序列化和反序列化過(guò)程中 都會(huì)忽略這個(gè)屬性
-
@JsonManagedReference
正常序列化 反序列化
-
@JsonBackReference
序列化data to json過(guò)程中 ,會(huì)忽略這個(gè)屬性
@OneToMany和@ManyToOne要素
-
cascade
一的一方一般用: cascade = CascadeType.ALL
多的一方不用設(shè)置,默認(rèn)不級(jí)聯(lián)
-
fetch
默認(rèn)是lazy還是eager啊
-
mappedby
或者joinColumn
一的一方用mappedby
多的一方用joinColumn
-
orphanRemove
一的一方用這個(gè): orphanRemove=true
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/JsongNeu/article/details/105233824