Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.4
  Go To Table Of Contents


Use the @JoinFetch annotation to enable the joining and reading of the related objects in the same query as the source object.


You should set join fetching at the query level, as not all queries require joining.

Annotation Elements

Table 2-28 describes this annotation's elements.

Table 2-28 @JoinFetch Annotation Elements

Annotation Element Description Default


(Optional) Set this attribute to the org.eclipse.persistence.annotations.JoinFetchType enumerated type of the fetch that you will be using.

The following are the valid values for the JoinFetchType:

  • INNER—This option provides the inner join fetching of the related object.

    Note: Inner joining does not allow for null or empty values.

  • OUTER—This option provides the outer join fetching of the related object.

    Note: Outer joining allows for null or empty values.



You can specify the @JoinFetch annotation for the following mappings:

Alternatively, you can use batch fetching which is more efficient, especially for collection relationships.


The following example shows how to use the @JoinFetch annotation to specify Employee field managedEmployees.

Example 2-52 Using @JoinFetch Annotation

 public class Employee implements Serializable {
    @OneToMany(cascade=ALL, mappedBy="owner")
    public Collection<Employee> getManagedEmployees() {
        return managedEmployees;

Example 2-53 shows how to use this extension in the eclipselink-orm.xml file.

Example 2-53 Using <join-fetch> in XML

<one-to-many name="managedEmployees">

See Also

For more information, see: