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 |
|||
Line 19: | Line 19: | ||
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> | + | * <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> | + | * <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>[[#How to Use the @BasicCollection Annotation|@BasicCollection]]</tt> | ||
Line 28: | Line 28: | ||
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 | ||
− | |note=We recommend setting join fetching at the query level, as not all queries require joining | + | |note=We recommend setting join fetching at the query level, as not all queries require joining. |
}} | }} | ||
− | Alternatively, you can use batch reading, especially for collection relationships. | + | Alternatively, you can use batch reading, especially for collection relationships.]]. |
{{EclipseLink_AttributeTable | {{EclipseLink_AttributeTable | ||
Line 43: | Line 43: | ||
* <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> | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</td> | </td> | ||
<td><tt>JoinFetchType.INNER</tt></td> | <td><tt>JoinFetchType.INNER</tt></td> |
Revision as of 10:49, 28 April 2011
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
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:
- @OneToOne
- @OneToMany
- @ManyToOne
- @ManyToMany
- @BasicCollection
- @BasicMap
Using the @JoinFetch annotation, you can 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.
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; } ... }