Use eclipselink.query-results-cache
to specify that the query should use a results cache.
Values
Table 4-27 describes this persistence property's values.
Table 4-27 Valid Values for query-results-cache
Value | Description |
---|---|
|
(Default) |
|
Query results are cache. |
|
Query results are not cached. |
Usage
By default, the query will cache 100 query results (see query-results-cache.size); if the same named query with the same arguments is re-executed EclipseLink will skip the database and return the cached results.
Note: The query cache is different and independent from the object cache. |
Examples
Example 4-54 Using query-results-cache in a JPA Query
import org.eclipse.persistence.config.HintValues; import org.eclipse.persistence.config.QueryHints; query.setHint("eclipselink.QUERY_RESULTS_CACHE", "TRUE");
Example 4-55 Using query-results-cache in a @QueryHint Annotation
import org.eclipse.persistence.config.HintValues; import org.eclipse.persistence.config.QueryHints; @QueryHint(name=QueryHints.QUERY_RESULTS_CACHE, value="TRUE");
Example 4-56 Using query-results-cache in orm.xml File
<?xml version="1.0"?> <entity-mappings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd" version="2.4"> <entity name="Employee" class="org.acme.Employee" access="FIELD"> <named-query name="findAllEmployeesInCity" query="Select e from Employee e where e.address.city = :city"> <hint name="eclipselink.query-results-cache" value="true"/> <hint name="eclipselink.query-results-cache.size" value="500"/> </named-query> ... </entity> </entity-mappings>
See Also
For more information, see:
"About Query Results Cache" in Understanding EclipseLink