Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Relationship Mappings/Common Relationship Configurations/JoinFetch"
m |
m |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | {{EclipseLink_UserGuide | + | {{EclipseLink_UserGuide |
− | | | + | |info=y |
− | + | |toc=n | |
− | = | + | |eclipselink=y |
− | + | |eclipselinktype=JPA | |
− | + | |api=y | |
+ | |apis= | ||
+ | * [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/annotations/JoinFetch.html @JoinFetch] | ||
− | == | + | }} |
− | + | =@JoinFetch= | |
− | + | 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 | ||
+ | |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: | ||
− | < | + | * <tt>@OneToOne</tt> |
− | + | * <tt>[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings/OneToMany|@OneToMany]]</tt> | |
− | < | + | * <tt>@ManyToOne</tt> |
− | + | * <tt>[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings/ManyToMany|@ManyToMany]]</tt> | |
− | + | * <tt>@BasicCollection</tt> (deprecated) | |
− | + | * <tt>@BasicMap</tt> (deprecated) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </ | + | |
− | |||
− | + | Alternatively, you can use batch reading, especially for collection relationships.]]. | |
+ | {{EclipseLink_AttributeTable | ||
+ | |caption=@JoinFetch Annotation Attributes | ||
+ | |content=<tr> | ||
+ | <td>'''<tt>value</tt>'''</td> | ||
+ | <td>Set this attribute to the <tt>org.eclipse.persistence.annotations.JoinFetchType</tt> enumerated type of the fetch that you will be using. | ||
− | < | + | The following are the valid values for the <tt>JoinFetchType</tt><nowiki>:</nowiki> |
− | + | * <tt>INNER</tt> – This option provides the inner join fetching of the related object.<br>Note: Inner joining does not allow for null or empty values. | |
+ | * <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> | ||
− | |||
− | < | + | </td> |
− | // | + | <td><tt>JoinFetchType.INNER</tt></td> |
− | + | <td>No</td> | |
− | + | </tr> | |
− | + | }} | |
− | + | ||
− | + | ||
− | / | + | |
− | + | ||
− | + | ||
− | </ | + | |
− | |||
− | + | The following example shows how to use the <tt>@JoinFetch</tt> annotation to specify <tt>Employee</tt> field <tt>managedEmployees</tt>. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | <span id="Example: @JoinFetch Annotation"></span> | ||
+ | ======''Example: @JoinFetch Annotation''====== | ||
<source lang="java"> | <source lang="java"> | ||
− | + | @Entity | |
− | + | public class Employee implements Serializable { | |
− | + | ... | |
− | + | @OneToMany(cascade=ALL, mappedBy="owner") | |
− | + | @JoinFetch(value=OUTER) | |
− | + | public Collection<Employee> getManagedEmployees() { | |
− | + | return managedEmployees; | |
+ | } | ||
+ | ... | ||
+ | } | ||
</source> | </source> | ||
+ | |||
Line 79: | Line 70: | ||
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings|Collection Mappings]] | |next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings|Collection Mappings]] | ||
|up=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Relationship_Mappings/Common_Relationship_Configurations|Common Relationship Configurations]] | |up=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Relationship_Mappings/Common_Relationship_Configurations|Common Relationship Configurations]] | ||
− | |version=2. | + | |version=2.2.0 DRAFT}} |
Latest revision as of 12:07, 17 May 2011
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
@JoinFetch
Use the @JoinFetch annotation to enable the joining and reading of the related objects in the same query as the source object.
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:
- @OneToOne
- @OneToMany
- @ManyToOne
- @ManyToMany
- @BasicCollection (deprecated)
- @BasicMap (deprecated)
Alternatively, you can use batch reading, especially for collection relationships.]].
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:
|
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; } ... }