Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


@JoinFetch

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


NoteNote:

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

value

(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.

JoinFetchType.INNER



Usage

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

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


Examples

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

Example 2-52 Using @JoinFetch Annotation

@Entity
 public class Employee implements Serializable {
    ...
    @OneToMany(cascade=ALL, mappedBy="owner")
    @JoinFetch(value=OUTER)
    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">
    <join-fetch>OUTER</join-fetch>
</one-to-many>


See Also

For more information, see: