Use eclipselink.join-fetch hint to join attributes in a query.
|
Use dot notation to access nested attributes. For example, to batch-read an employee's manager's address, use |
Values
Table 4-21 describes this query hint's valid values.
Usage
This hint is similar to eclipselink.batch. Subsequent queries of related objects can be optimized in batches instead of being retrieved in one large joined read
The eclipselink.join-fetch hint differs from JPQL joining in that it allows multilevel fetch joins.
Examples
Example 4-42 shows how to use this hint in a JPA query.
Example 4-42 Using join-fetch in a JPA Query
import org.eclipse.persistence.config.HintValues;
import org.eclipse.persistence.config.QueryHints;
query.setHint("eclipselink.join-fetch", "e.address");
Example 4-43 shows how to use this hint with the @QueryHint annotation.
Example 4-43 Using join-fetch in a @QueryHint Annotation
import org.eclipse.persistence.config.HintValues; import org.eclipse.persistence.config.QueryHints; @QueryHint(name=QueryHints.FETCH, value="e.address");
See Also
For more information, see:
"EclipseLink" JPA Query Hints
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Query_Hints
EclipseLink Examples
http://wiki.eclipse.org/EclipseLink/Examples/JPA/QueryOptimization
"Optimizing Queries" in Understanding EclipseLink.
"Fetch Joins" in the JPA Specification (http://jcp.org/en/jsr/detail?id=317)
"Enhancing Performance" in Solutions Guide for EclispeLink