It is often better to execute two simpler SQL queries than one functionally identical complex SQL query.
Does Hibernate ever tries to use this optimalization for HQL (or Criterias or whatever) or does it always generate just one SQL?
You may ask, why don't I just write two HQL queries, just like in SQL. Consider this for example:
from User
Trivial HQL query, but it may generate very complicated SQL, because of all eager loaded associations.
Hibernate could theoretically execute just the basic query (SELECT * FROM user), gather One-To-One and One-To-Many references (ids) and then do second query to gather rows for these ids etc. This could be faster, especially when cardinality of reference ids in User is low (it would then produce smaller network traffic).
The question is, whether Hibernate (or possibly some other JPA implementation?) can use this kind of optimalization?
Thanks.