ramsafin / recommendation-engine

Spring Boot recommendation engine web application
2 stars 1 forks source link

Hibernate pagination issue when joining tables #10

Open ramsafin opened 7 years ago

ramsafin commented 7 years ago

Suppose, we have 3 tables posts <= posts_tags => tags.

In our Spring Data repository:

// in PostRepository.java

@Query("select p from Post p left join fetch p.tags")
List<Post> findAll(Pageable pageable);

This is gonna be cartesian product and Hibernate cannot limit it or something else without doing it in memory when ALL this censored result is selected.
Let's imagine, we have 1000 posts each of them has 3-5 tags. This is gonna be the HELL!

ramsafin commented 7 years ago

Most likely, I have to write native SQL here (