Let's say I have entities A, B, C and each A has many B and C entities. I want to query a load of A entities based on some criterea, and I know I will be accessing all B and C entities for each A I return.
Something like select a from A as a join fetch a.b join fetch a.c
would seem to make sense at first, but this creates a huge product if the numbers of B and C entities are large. Extending this to another associated entities makes the query totally unreasonable.
If I leave JPA to its own devices, I end up with n+1 selects when it wants to access the B and C entities.
What I thought I'd do was query A join fetch B, then A join fetch C, but this doesn't work as it gives me two List<A>
results each with only half the information.
This is a pretty simple query in SQL terms, and I'm disappointed there isn't an obvious way to handle this. Am I missing something?
Provider is toplink essentials