Details
Description
I analysed the query generated because I had some performance problems.
I saw that the joins are created for each FIQL expression.
If two FIQL expressions require the same join it's not necessary to create two joins.
I enabled the log to display the query with hibernate:
add this line <property name="hibernate.show_sql" value="true"/> in persistance.xml
I launched the following unit test: JPATypedQueryVisitorTest.testAndQueryCollection
The query result is:
select book0_.id as id0_, book0_.houseNumber as houseNum2_0_, book0_.street as street0_, book0_.bookTitle as bookTitle0_, book0_.library_id as library7_0_, book0_.dateOfBirth as dateOfBi5_0_, book0_.thename as thename0_ from Book book0_ inner join Book_authors authors1_ on book0_.id=authors1_.Book_id inner join Book_BookReview reviews2_ on book0_.id=reviews2_.Book_id inner join BookReview bookreview3_ on reviews2_.reviews_id=bookreview3_.id inner join Book_BookReview reviews4_ on book0_.id=reviews4_.Book_id inner join BookReview bookreview5_ on reviews4_.reviews_id=bookreview5_.id inner join BookReview_authors authors6_ on bookreview5_.id=authors6_.BookReview_id where cast(book0_.id as integer)=10 and authors1_.authors=? and bookreview3_.review=? and authors6_.authors=?
There are two "inner join" which are not necessary because they are duplicated.
The query could be:
select book0_.id as id0_, book0_.houseNumber as houseNum2_0_, book0_.street as street0_, book0_.bookTitle as bookTitle0_, book0_.library_id as library7_0_, book0_.dateOfBirth as dateOfBi5_0_, book0_.thename as thename0_ from Book book0_ inner join Book_authors authors1_ on book0_.id=authors1_.Book_id inner join Book_BookReview reviews2_ on book0_.id=reviews2_.Book_id inner join BookReview bookreview3_ on reviews2_.reviews_id=bookreview3_.id inner join BookReview_authors authors4_ on bookreview3_.id=authors4_.BookReview_id where cast(book0_.id as integer)=10 and authors1_.authors=? and bookreview3_.review=? and authors4_.authors=?