I know you can control fetching behaviour using @javax.persistence.FetchType, however can you control the fetching programmatically from within a JPA Criteria query? Basically I can tell from the query what part of the application is likely calling and what part of the model will (most likely) be needed.
I couldn't find an answer in any of the tutorials but these old questions:
- NHibernate manually control fetching which is about NHibernate and has non-answers
- How do you programmatically turn off eager fetching with hibernate? which doesn't mention the criteria API, and is so ancient as not to make this question an automatic duplicate, however I suspect the answer may still be the current situation.
- JPA & Criteria API - Select only specific columns which is about returning tuples and not the model itself
tl;dr: can you control the fetching programmatically from within a JPA Criteria query?