英文:
implementation issue on @OneToMany relationship recursive call infinite loop
问题
我有两个类别,城市和宗教场所,一个城市可以拥有多个宗教场所,但一个宗教场所只能属于一个城市,但按要求实施时,我遇到了一个错误,我的响应卡在递归调用中。
我期望得到所请求城市中所有宗教场所的响应。
英文:
I've two classes city and religious places where a city can have multiple religious places, but a religious place can have only one city, but when I implement as per requirement I got an error my response stuck in the recursive call.
I am expecting response of all religious places which is located in requested city
答案1
得分: 1
你可以通过在City类的religious places字段和ReligiousPlace类的city字段上添加@JsonIgnore来告诉Jackson在序列化期间忽略特定数据。
@Entity
@Table(name = "religious_places")
class ReligiousPlace {
@ManyToOne
@JoinColumn(name = "city_id")
@JsonIgnore
private City city;
}
@Entity
@Table(name = "city")
class City {
@OneToMany(mappedBy = "city", cascade = CascadeType.ALL)
@JsonIgnore
private List<ReligiousPlace> religious_places;
}
英文:
You may tell Jackson to disregard certain data during serialisation by adding @JsonIgnore to the religious places field in the City class and the city field in the ReligiousPlace class.
@Entity
@Table(name = "religious_places")
class ReligiousPlace {
@ManyToOne
@JoinColumn(name = "city_id")
@JsonIgnore
private City city;
}
@Entity
@Table(name = "city")
class City {
@OneToMany(mappedBy = "city", cascade = CascadeType.ALL)
@JsonIgnore
private List<ReligiousPlace> religious_places;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论