jpa实体@ManyToOne @OneToMany无限递归方式

 更新时间:2021年10月18日 08:44:34   作者:宋大王  
这篇文章主要介绍了jpa实体@ManyToOne @OneToMany无限递归方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

jpa实体@ManyToOne @OneToMany无限递归

问题描述

Cannot call sendError() after the response has been committed

在这里插入图片描述

解决办法

在属性上添加注释

    @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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

最新评论