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

From Eclipsepedia

Jump to: navigation, search
m
m
 
(5 intermediate revisions by one user not shown)
Line 7: Line 7:
 
|api=y
 
|api=y
 
|apis=
 
|apis=
* [http://www.eclipse.org/eclipselink/api/latest/javax/persistence/FetchType.html FetchType]
+
* [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/annotations/JoinFetch.html @JoinFetch]  
 +
 
 
}}
 
}}
=Fetch Type=
+
=@JoinFetch=
By default, EclipseLink persistence provider uses a fetch type of <tt>javax.persitence.FetchType.EAGER:</tt> 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 <tt>FetchType.LAZY:</tt> 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 <tt>FetchType.LAZY</tt> on all relationships.
+
  
You are not required to provide value for this attribute.
+
Use the <tt>@JoinFetch</tt> annotation to enable the joining and reading of the related objects in the same query as the source object.
 
+
{{EclipseLink_Note
==How to Use the @JoinFetch Annotation==
+
|note=We recommend setting join fetching at the query level, as not all queries require joining.
 +
}}
  
 
You can specify the <tt>@JoinFetch</tt> annotation for the following mappings:
 
You can specify the <tt>@JoinFetch</tt> annotation for the following mappings:
  
* <tt>[[Introduction%20to%20EclipseLink%20JPA%20(ELUG)#@OneToOne|@OneToOne]]</tt>
+
* <tt>@OneToOne</tt>
 
* <tt>[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings/OneToMany|@OneToMany]]</tt>
 
* <tt>[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings/OneToMany|@OneToMany]]</tt>
* <tt>[[Introduction%20to%20EclipseLink%20JPA%20(ELUG)#@ManyToOne|@ManyToOne]]</tt>
+
* <tt>@ManyToOne</tt>
 
* <tt>[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings/ManyToMany|@ManyToMany]]</tt>
 
* <tt>[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings/ManyToMany|@ManyToMany]]</tt>
* <tt>[[#How to Use the @BasicCollection Annotation|@BasicCollection]]</tt>
+
* <tt>@BasicCollection</tt> (deprecated)
* <tt>[[#How to Use the @BasicMap Annotation|@BasicMap]]</tt>
+
* <tt>@BasicMap</tt> (deprecated)
  
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
 
|note=We recommend setting join fetching at the query level, as not all queries require joining. For more information, see [[Using%20Basic%20Query%20API%20(ELUG)#Using Join Reading with ObjectLevelReadQuery|Using Join Reading with ObjectLevelReadQuery]].
 
}}
 
  
Alternatively, you can use batch reading, especially for collection relationships. For more information, see [[Using%20Basic%20Query%20API%20(ELUG)#Using_Batch_Reading|Using Batch Reading]].
+
Alternatively, you can use batch reading, especially for collection relationships.]].
  
 
{{EclipseLink_AttributeTable
 
{{EclipseLink_AttributeTable
|caption=@JoinFetch Annotation.Attributes
+
|caption=@JoinFetch Annotation Attributes
 
|content=<tr>
 
|content=<tr>
 
  <td>'''<tt>value</tt>'''</td>
 
  <td>'''<tt>value</tt>'''</td>
Line 42: Line 39:
 
* <tt>OUTER</tt> – This option provides the outer join fetching of the related object.<br>Note: Outer joining allows for null or empty values.<br>
 
* <tt>OUTER</tt> – This option provides the outer join fetching of the related object.<br>Note: Outer joining allows for null or empty values.<br>
  
For more information, see the following:
+
 
* [[Introduction%20to%20EclipseLink%20Expressions%20(ELUG)#What You May Need to Know About Joins|What You May Need to Know About Joins]]
+
* [[Using%20Basic%20Query%20API%20(ELUG)#Using Join Reading with ObjectLevelReadQuery|Using Join Reading with ObjectLevelReadQuery]]
+
* [[Configuring%20a%20Relational%20Mapping%20(ELUG)#Configuring Joining at the Mapping Level|Configuring Joining at the Mapping Level]]
+
 
  </td>
 
  </td>
 
  <td><tt>JoinFetchType.INNER</tt></td>
 
  <td><tt>JoinFetchType.INNER</tt></td>

Latest revision as of 12:07, 17 May 2011

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Elug api package icon.png Key API

[edit] @JoinFetch

Use the @JoinFetch annotation to 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.

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


Alternatively, you can use batch reading, especially for collection relationships.]].

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


JoinFetchType.INNER No


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

[edit] 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...