0

I have an entity account that I would like to link with another entity account.

When testing with postman I get a StackOverflowError because the list of friends is reloaded to infinity

What can I do to solve my problem?



public class Account {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
   

    @ManyToMany
    @JoinTable(name = "ludo",
            joinColumns = @JoinColumn(name = "id_account"),
            inverseJoinColumns = @JoinColumn(name = "id_boardGame"))
    private List<Boardgame> boardgameList;



    @OneToMany(mappedBy = "friend")
    List<Friends> FriendsList;
    
}


@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Friends {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id_friends;

    @JsonIgnore
    @OneToOne
    @JoinColumn(name="FK_account", referencedColumnName="account_id")
    private Account account;


    @OneToOne( fetch = FetchType.LAZY)
    @JoinColumn(name="FK_friend",nullable = false, referencedColumnName="account_id")
    private Account friend;

    @Column(updatable = false)
    @CreationTimestamp
    private LocalDateTime createdAt;

}
Orel M
  • 1
  • 1

0 Answers0