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 The following are the valid values for the
|
|
Usage
You can specify the @JoinFetch
annotation for the following mappings:
@OneToOne
@OneToMany
@ManyToOne
@ManyToMany
@ElementCollection
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:
Understanding EclipseLink
"Enhancing Performance" in Solutions Guide for EclispeLink