JPA Bidirectional Link - Infinite Loop / Circular Link
I have bi-directional communication
@Entity
@Table(name = "facility")
public class Facility implements Serializable {
@Id
@GeneratedValue
private Long id;
@OneToMany(mappedBy = "facility")
private Set<Amenity> amenities;
}
@Entity
@Table(name = "amenity")
public class Amenity implements Serializable {
@Id
@GeneratedValue
private Long id;
@ManyToOne
private Facility facility;
}
Everything works fine and I can see that the table has been created correctly. I can add data to the rest endpoint, but that was only when I wanted to go the opposite direction and get a convenience facility when I had this problem. It looks like it goes into an infinite loop, the object calls amenity calls a convenience call and so on. It looks like a circular link. I have searched high and low, far and wide and followed many examples and all seem to have objects created in a similar way. I have left getters and setters for brevity. I expect that after it gets its first convenience it will stop.
[
{
"id": 1,
"facilityName": "asdf",
"facilityCode": "asdf",
"amenities": [
{
"id": 15,
"amenityType": "amenity 1",
"facility": {
"id": 1,
"facilityName": "asdf",
"facilityCode": "asdf",
"amenities": [
{
+4
user1918261
source
to share
No one has answered this question yet
See similar questions:
0
or similar:
416
341
40
3
2
1
1
1
0
0