hibernate subselect performance issue due to redundant load -
user(m:m)books @entity public class user{ @id public int id; @manytomany(fetch = fetchtype.lazy, targetentity = book.class) @jointable(name = "user_book", joincolumns = @joincolumn(name = "user_id"), inversejoincolumns = @joincolumn(name = "book_id")) @fetch(fetchmode.subselect) public list<book> books; } @entity public class book{ @id public int id; ... } loadallactiveusers() foreach user do(user.books)
suppose have 1000 users each of them have books (we have 1000 books). when call user.books hibernate trigger query:
select book.* association inner join books b on b.id = association.book_id association.user_id in (select u.id users u)
this query has result of 1m rows although have 1000 books. because hibernate load user_id , not book_id.
if hibernate join of association in clause result limit distinct books , not query duplicate books.
select book.* books b.id in (select association.book_id users u join association on a.user_id = u.id)
is there way tell hibernate subselect in 2 steps : id of associated , associated entity?
Comments
Post a Comment