Short answer depends.
For any provider JPA you can really configure the way you want the provider to generate queries.
It does not matter what kind of API you are using - whether it be writing HQL/JPQL or using Criteria queries or using criteria builder - they all generate queries based on how you have configured JPA/Hibernate.
Specifically for you question since you are using Hibernate as your provider you can set fetching strategies. FetchType and FetchMode.
Fetch types can be {Lazy, Eager}
But you will be interested in FetchMode which could be one of the following
FetchMode.SELECT, FetchMode.JOIN, FetchMode.SUBSELECT
Depending on the combination of FetchMode
and FetchType
you use, you can strongly define how Hibernate generates the queries. For example, FetchMode.JOIN
will use a JOIN
to fetch results and relationships in a single query while FetchMode.SELECT
will use a different query for child relationships.
You can read more about this in the Hibernate documentation. http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/performance.html#performance-fetching