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
reference jpa circular-reference relationship circular


source to share


No one has answered this question yet

See similar questions:

0
jpa bidirectional link binding error

or similar:

416
MongoDB relationships: embedding or linking?
341
Create the perfect JPA object
40
Wrong ordering in generated table in jpa
3
Hibernate: Why does the FetchType.LAZY-annotated collection property eagerly load?
2
Java JPA (EclipseLink) How do I get the next GeneratedValue before storing the actual object?
1
Why is there a 0 ... 1 Relationship with the join table?
1
Lazy load doesn't work - I only need the parent object, not all associations
1
Advanced JPA with pivot table
0
JPA one to many no join table
0
JPA ManyToMany relationship: why will the join table be empty?



All Articles
Loading...
X
Show
Funny
Dev
Pics