2

I have QueryDsl query with Spring jpa written like:

JPAQuery<FooEntity> query = getQuerydsl()
        .<FooEntity>createQuery()
        .from(foo)
        .leftJoin(foo.bar, bar).fetchJoin()
        .leftJoin(...).fetchJoin()
        .where(predicate)
        .distinct();
    return new PageImpl<>(getQuerydsl().applyPagination(pageable, query).fetch(), pageable,
        query.fetchCount());

FetchJoin is used because data from joined tables is needed. The strange thing is that some of these queries have correct SQL ending on limit ?,?. It means pagination is applied inside the database.

But if the mapping is done via @OneToMany(mappedBy = "...") and not @JoinColumn(), then all data is loaded into memory and I see the warning:

HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!

How to avoid loading all data into memory in this case?

Nikita
  • 4,435
  • 3
  • 24
  • 44
  • Please give a look in [this thread](https://stackoverflow.com/questions/11431670/how-can-i-avoid-the-warning-firstresult-maxresults-specified-with-collection-fe) . It seems that is more a jpa related issue than query dsl's. – leopal Jul 04 '18 at 08:44

0 Answers0