Use eclipselink.left-join-fetch
to optimize the query: related objects will be joined into the query instead of being queries separately.
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 |
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 OUTER
join to allow null or empty values.
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");
"Fetch Joins" in the JPA Specification (http://jcp.org/en/jsr/detail?id=317
)
"Enhancing Performance" in Solutions Guide for Oracle TopLink