0

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

Community
  • 1
  • 1
villat
  • 65
  • 1
  • 8
  • Possible duplicate of [Solve "failed to lazily initialize a collection of role" exception](http://stackoverflow.com/questions/11746499/solve-failed-to-lazily-initialize-a-collection-of-role-exception) – OldProgrammer Feb 26 '17 at 19:36
  • @OldProgrammer That isn't exactly the same. That is only for the case of 1 collection, this question is specific to how to handle multiple collections simultaneously. – Naros Feb 26 '17 at 19:39
  • @OldProgrammer, yea, my question is about multiple collections. as i know, you can't join fetch 2+ collections – villat Feb 26 '17 at 21:30

0 Answers0