I have for example i have project with this entities : Category
, Author
, Book
,book_language
and publisher
.
Book
has Many-to-Many relations with Category
and Author
, and Many-to-One with book_language
and publisher
.
i need to update values in already created object:
Controller code:
public String update(@PathVariable int id, Model model){
model.addAttribute("book",bookService.readOne(id));
return show(model);
Controller calls service method, which calls DAO method. DAO method with query:
@Query("SELECT b from Book b LEFT join fetch b.book_language left join fetch b.publisher " +
"left join fetch b.categories where b.id = ?1")
Book readOne(int id);
And there is problem: i can't join fetch 2 many-to-many relations, but i need to, because i had Failed to lazily initialize a collection of role no Session
exception.
So my question is: how should i correctly load these entities?
UPD: Solve "failed to lazily initialize a collection of role" exception This question is about one MtM relation, and my is about 2 or more