An example of stack overflow when get an object using java quarkus reactive panache:
@Table(name = "author")
public class Author extends PanacheEntityBase {
private Long id;
private String authorName;
@OneToMany(fetch = FetchType.LAZY)
private Set<Book> books;
}
---------
@Table(name = "book")
public class Book extends PanacheEntityBase {
private Long id;
private String bookName;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id")
private Author author;
@ManyToMany(fetch = FetchType.LAZY)
private Set<Publisher> publishers;
}
---------
@Table(name = "publisher")
public class Publisher extends PanacheEntityBase {
private Long id;
private String publisherName;
@ManyToMany(fetch = FetchType.LAZY)
@JoinColumn(...)
private Set<Book> books;
}
I do find
an author and got error with LazyInitializationException.
return find("authorId", id).firstResult()
.onItem().call(au -> Mutiny.fetch(au.books())); Root cause: Bi-directional relationships between authors and publishers can result in an infinite loop of related entities.
Of course, if I map it to a DTO object with no relationships, the problem is solved. Reffered link: https://github.com/quarkusio/quarkus/issues/23757 The problem is that I want to keep working something with Author, not AuthorDTO...