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.
Difference between revisions of "EclipseLink/Examples/JPA/QueryOptimization"
m (xrefs to elug) |
|||
Line 1: | Line 1: | ||
EclipseLink allows users the option to optimize their queries using batch and joined reading through the use of a query hints. | EclipseLink allows users the option to optimize their queries using batch and joined reading through the use of a query hints. | ||
− | See | + | See: |
+ | * [[Optimizing_the_EclipseLink_Application_%28ELUG%29#Optimizing_Queries|Optimizing Queries]] in the ''[[EclipseLink/UserGuide|EclipseLink User's Guide]]'' | ||
+ | * [[Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Query_Customization_Extensions|Using EclipseLink JPA Query Customization Extensions]] in the ''[[EclipseLink/UserGuide|EclipseLink User's Guide]]'' | ||
+ | *[[Optimizing_the_EclipseLink_Application_%28ELUG%29#How_to_Use_Batch_and_Join_Reading_for_Optimization|How to Use Bach and Join Reading]] in the ''[[EclipseLink/UserGuide|EclipseLink User's Guide]]'' | ||
+ | *org.eclipse.persistence.jpa.config.EclipseLinkQueryHints | ||
+ | |||
== Batch Reading == | == Batch Reading == |
Revision as of 08:29, 30 January 2008
EclipseLink allows users the option to optimize their queries using batch and joined reading through the use of a query hints.
See:
- Optimizing Queries in the EclipseLink User's Guide
- Using EclipseLink JPA Query Customization Extensions in the EclipseLink User's Guide
- How to Use Bach and Join Reading in the EclipseLink User's Guide
- org.eclipse.persistence.jpa.config.EclipseLinkQueryHints
Contents
Batch Reading
Configures the query to optimize the retrieval of the related objects, the related objects for all the resulting objects will be read in a single query (instead of n queries). Valid values are strings that represent JPQL style navigations to a relationship. e.g. e.manager.phoneNumbers
Via Annotations
@Entity
@Table(name="JPA_EMPLOYEE")
@NamedQuery(
name="findAllEmployees",
query="SELECT e FROM Employee e order by e.id"),
hints={
@QueryHint(
name=EclipseLinkQueryHints.BATCH,
value="e.manager.phoneNumbers")
}
)
public class Employee implements Serializable {
...
}
Via XML
<entity name="Employee" class="org.eclipse.testing.Employee" access="PROPERTY">
...
<named-query name="findAllEmployees">
<query>SELECT e FROM Employee e order by e.id</query>
<hint name="eclipselink.batch" value="e.manager.phoneNumbers">
</named-query>
...
</entity>
Joined Reading
Configures the query to optimize the retrieval of the related objects, the related objects will be joined into the query instead of being queried independently. This allow for nested join fetching which is not supported in JPQL. Valid values are strings that represent JPQL style navigations to a relationship. e.g. e.manager.phoneNumbers
Via Annotations
@Entity
@Table(name="JPA_EMPLOYEE")
@NamedQuery(
name="findAllEmployeesByFirstName",
query="SELECT OBJECT(employee) FROM Employee employee WHERE employee.firstName = :firstname"),
hints={
@QueryHint(
name=EclipseLinkQueryHints.FETCH,
value="e.manager.phoneNumbers")
}
)
public class Employee implements Serializable {
...
}
Via XML
<entity name="Employee" class="org.eclipse.testing.Employee" access="PROPERTY">
...
<named-query name="findAllEmployeesByFirstName">
<query>SELECT OBJECT(employee) FROM Employee employee WHERE employee.firstName = :firstname</query>
<hint name="eclipselink.join-fetch" value="e.manager.phoneNumbers">
</named-query>
...
</entity>