Springboot jpa 一對多保存實體時報錯無限循環

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="crmUserId")
private CrmUser crmUser;

報錯信息

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.swj.crm.entity.topline.CompanyUser["crmUser"]->com.swj.crm.entity.topline.CrmUser["companyUsers"]->org.hibernate.collection.internal.PersistentBag[0]->com.swj.crm.entity.topline.CompanyUser["crmUser"]->com.swj.crm.entity.topline.CrmUser["companyUsers"]->org.hibernate.collection.internal.PersistentBag[0]-
....

解決方法

@JsonBackReference
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="crmUserId")
private CrmUser crmUser;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章