Use eclipselink.left-join-fetch
to optimize the query: related objects will be joined into the query instead of being queries separately.
Values
Table 4-22 describes this query hint's values.
Table 4-22 Valid Values for left-join-fetch
Value | Description |
---|---|
String |
JPQL-style navigations to a relationship |
Usage
You can use this query hint to create nested join fetches, which is not supported by JPQL. You can also use eclipselink.left-join-fetch
to create join fetches with native queries.
Note: This uses an |
Examples
Example 4-44 Using left-join-fetch in a JPA Query
import org.eclipse.persistence.config.HintValues; import org.eclipse.persistence.config.QueryHints; query.setHint("eclipselink.LEFT_FETCH", "STRING");
Example 4-45 Using left-join-fetch in a @QueryHint Annotation
import org.eclipse.persistence.config.HintValues; import org.eclipse.persistence.config.QueryHints; @QueryHint(name=QueryHints.LEFT_FETCH, value="STRING");
See Also
EclipseLink Examples
http://wiki.eclipse.org/EclipseLink/Examples/JPA/QueryOptimization
"Fetch Joins" in the JPA Specification (http://jcp.org/en/jsr/detail?id=317
)
"Enhancing Performance" in Solutions Guide for EclispeLink