java - 使用@JsonIdentityInfo 或@JsonManagedReference,@JsonBackReference 会导致我在类中的属性在解析时被忽略
问题描述
我一直有休眠循环依赖问题,这是下面的类:
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="id")
public class Task extends DefaultEntity{
@ManyToOne
@JoinColumn(name = "cloth_model_id")
//@JsonIgnore
private ClothModel clothModel;
private String details;
private boolean completed;
@ManyToOne
@JoinColumn(name = "employee_id")
private Employee employee;
}
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="id")
public class ClothModel extends DefaultEntity {
private ClothingType clothingType;
private int quantity;
private double amount;
@Transient
private String modelStructure;
private String savedUrl;
@Transient
//@JsonManagedReference
private List<Task> tasks = new ArrayList<>();
}
@MappedSuperclass
public class DefaultEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "serial")
private long id;
@Column(name = "Time",columnDefinition= "TIMESTAMP WITH TIME ZONE")
@Temporal(TemporalType.TIMESTAMP)
private Date dateCreated;
我删除了 getter 和 setter,所以代码不会太多
当我将@JsonIdentityInfo 或@JsonManagedReference、@JsonBackReference 应用于 ClothModel.class 和 Task.class 时,我注意到当我尝试向其写入 JSON 时,Task.class 中的clothModel 属性将被忽略,它的行为就像我正在使用@Jsonignore 注释。为什么会这样,为什么没有针对 Hibernate 循环递归的适当 100% 工作修复。
解决方案
推荐阅读
- swift - Xcode ViewController 更改问题
- python - 嵌套while循环在python中不起作用
- android - 不能只在一个方向上滑动 ViewPager2
- .net - 考虑到 Azure .NET Web 应用程序中的 SNAT 端口限制,对于数千个调用的最佳并行化策略是什么?
- spring-boot - 使用 spring-jpa 搜索登录用户的记录
- javascript - 在 props 准备好之前渲染子组件
- javascript - Filtering a JS Array full of Objects to find multiple objects
- javascript - 如何将具有 id 的数组从一个组件传递到另一个组件(角度)
- ldap - 如何将 ACL 添加到 OpenLDAP 中的属性
- python - 处理另存为和保存按钮的功能不起作用