我目前正在运行一个spring-boot应用程序,其中端点返回存储在数据库中的特定对象的Page.为了我们的目的,我们称该对象为"x".在"x"中,有一个设置为延迟取出的对象列表.
@Entity
@DynamicUpdate
class x {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@JsonIgnore
@OneToMany(mappedBy = "x", cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private List<y> lazilyFetchedList;
@Override
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@JsonIgnore
public List<y> getLazilyFetchedList() {
return lazilyFetchedList;
}
public void setLazilyFetchedList(List<y> lazilyFetchedList) {
this.lazilyFetchedList = lazilyFetchedList;
}
}
Run Code Online (Sandbox Code Playgroud)
我在@JsonIgnore上面设置是因为我不希望lazilyFetchedList在GET呼叫时被发送到客户端.
我的问题是,尽管杰克逊作为查看JSON响应的客户端成功忽略了该字段.但是,当序列化Java对象"x"时,hibernate仍然会获取额外的查询lazilyFetchedList(即使jackson没有使用结果). …