Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Relationship Mappings/Common Relationship Configurations/JoinFetch"

m
Line 25: Line 25:
 
* <tt>[[#How to Use the @BasicMap Annotation|@BasicMap]]</tt>
 
* <tt>[[#How to Use the @BasicMap Annotation|@BasicMap]]</tt>
  
<source lang="java">
 
@Target({METHOD, FIELD})
 
@Retention(RUNTIME)
 
public @interface JoinFetch {
 
    JoinFetchType value() default JoinFetchType.INNER;
 
}
 
</source>
 
 
Using the <tt>@JoinFetch</tt> annotation, you can enable the joining and reading of the related objects in the same query as the source object.
 
Using the <tt>@JoinFetch</tt> annotation, you can enable the joining and reading of the related objects in the same query as the source object.
 
{{EclipseLink_Note
 
{{EclipseLink_Note
Line 40: Line 33:
  
 
{{EclipseLink_AttributeTable
 
{{EclipseLink_AttributeTable
|caption=<span id="Table 19-4">This table lists attributes of the <tt>@JoinFetch</tt> annotation.</span>
+
|caption=@JoinFetch Annotation.Attributes
 
|content=<tr>
 
|content=<tr>
 
  <td>'''<tt>value</tt>'''</td>
 
  <td>'''<tt>value</tt>'''</td>
Line 59: Line 52:
 
}}
 
}}
  
This example shows how to use the <tt>@JoinFetch</tt> annotation to specify <tt>Employee</tt> field <tt>managedEmployees</tt>.
 
  
<span id="Example 19-5"></span>
+
The following example shows how to use the <tt>@JoinFetch</tt> annotation to specify <tt>Employee</tt> field <tt>managedEmployees</tt>.
''''' Usage of the @JoinFetch Annotation'''''
+
 
 +
<span id="Example: @JoinFetch Annotation"></span>
 +
======''Example: @JoinFetch Annotation''======
 
<source lang="java">
 
<source lang="java">
 
  @Entity
 
  @Entity

Revision as of 15:16, 29 March 2011

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

Elug api package icon.png Key API

Fetch Type

By default, EclipseLink persistence provider uses a fetch type of javax.persitence.FetchType.EAGER: this is a requirement on the persistence provider runtime that data must be eagerly fetched.If the default is inappropriate for your application or a particular persistent field, set fetch to FetchType.LAZY: this is a hint to the persistence provider that data should be fetched lazily when it is first accessed (if possible). We recommend using the FetchType.LAZY on all relationships.

You are not required to provide value for this attribute.

How to Use the @JoinFetch Annotation

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

Using the @JoinFetch annotation, you can enable the joining and reading of the related objects in the same query as the source object.

Elug note icon.png

Note: We recommend setting join fetching at the query level, as not all queries require joining. For more information, see Using Join Reading with ObjectLevelReadQuery.

Alternatively, you can use batch reading, especially for collection relationships. For more information, see Using Batch Reading.

@JoinFetch Annotation.Attributes
Attribute Description Default Required?
value 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.

For more information, see the following:

JoinFetchType.INNER No


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

Example: @JoinFetch Annotation
 @Entity
 public class Employee implements Serializable {
     ...
     @OneToMany(cascade=ALL, mappedBy="owner")
     @JoinFetch(value=OUTER)
     public Collection<Employee> getManagedEmployees() {
         return managedEmployees;
     }
     ...
 }


Eclipselink-logo.gif
Version: 2.2.0 DRAFT
Other versions...

Copyright © Eclipse Foundation, Inc. All Rights Reserved.