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