I have few scenarios where the server queries objects from the database by using JPA and then sends the objects to the client over web services.
Since the client expects the full graph in such scenarios I would want to override the lazy loaded collections with eager loading and probably request for batch loading (for performance).
Is there a way in JPA (or EclipseLink) to override the query in a generic manner (without rewriting the query) and request the full graph?
10.1.3. Fetch Joins
JPQL queries may specify one or more join fetch declarations, which allow the query to specify which fields in the returned instances will be pre-fetched.
SELECT x FROM Magazine x join fetch x.articles WHERE x.title = 'JDJ'
The query above returns Magazine instances and guarantees that the articles field will already be fetched in the returned instances.
Multiple fields may be specified in separate join fetch declarations:
SELECT x FROM Magazine x join fetch x.articles join fetch x.authors WHERE x.title = 'JDJ'
Source : http://docs.oracle.com/cd/E13189_01/kodo/docs40/full/html/ejb3_overview_query.html#ejb3_overview_join_fetch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With