I have some nested objects, Package->Documents->Pages. The package contains a set of documents, the document contains a set of pages. I have the relationship with Pages->Documents and Documents->Pages both set to EAGER because when I request a package I want it to get all of the documents along with all of the pages.
Now I have another requirement to get only the Package->Documents, but I don't want to also retrieve Document->Pages because this query needs to be more efficient and doesn't need that data.
Is there a way using the same model objects that I can turn off the EAGER fetch? Or is there a way I can change it to LAZY and then force it to be eager without having to loop through every document in the package and call getPages()?
What's the preferred, most efficient way of doing this?
It's all explained here: Difference between JOIN and JOIN FETCH in Hibernate
Set your relationship to lazy and write a query using
join fetch
to eagerly retrieve all children while keeping your regular query with a simple join to get data lazily.