Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Query Cache"

(Query Results Cache)
(Query Results Cache)
Line 25: Line 25:
  
 
The query results cache is configured through query hints.
 
The query results cache is configured through query hints.
 +
 +
{{EclipseLink_HintTable
 +
|caption=Query Results Cache Query Hints
 +
|content=
 +
<tr>
 +
<td><tt>eclipselink.cache.coordination.protocol</tt></td>
 +
<td>Enable cache coordination using the communication protocol:
 +
* <tt>rmi</tt> - Use Java RMI to broadcast changes.
 +
* <tt>rmi-iiop</tt> - Use Java RMI over CORBA IIOP to broadcast changes.
 +
* <tt>jms</tt> - Use the Java Messaging Service to broadcast changes.
 +
* <tt>jms-publishing</tt> - Allows an EJB MessageDrivenBean to be used to broadcast changes.  The MDB must be configured separately.
 +
* <tt><class-name></tt> - The fully qualified class name of a custom implementation of a <code>TransportManager</code>.
 +
 +
</td>
 +
<td><tt>no coordination</tt></td>
 +
<td>Required</td>
 +
</tr>
 +
<tr>
 +
<td><tt>eclipselink.cache.coordination.channel</tt></td>
 +
<td>Sets the channel for cache coordination.  All persistence units using the same channel will be coordinated.
 +
</td>
 +
<td><tt>EclipseLinkCommandChannel</tt></td>
 +
<td>Required</td>
 +
</tr>
 +
<tr>
 +
}}
  
 
======''Query results cache annotation example''======
 
======''Query results cache annotation example''======

Revision as of 15:30, 28 May 2012

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

Elug api package icon.png Key API

Query Results Cache

The EclipseLink query results cache allows the results of named queries to be cached, similar to how objects are cached.

By default in EclipseLink all queries access the database, unless they are by Id, or by cache indexed fields. The resulting rows will still be resolved with the cache, and further queries for relationship will be avoided if the object is cached, but the original query will always access the database. EclipseLink does have options for querying the cache, but these options cannot be used by default, as EclipseLink cannot assume that all of the objects in the database are in the cache. The query results cache allows for non-indexed and result list queries to still benefit from caching.

The query results cache is indexed by the name of the query, and the parameters of the query. Only named queries can have their results cached, dynamic queries cannot use the query results cache. As well, if you modify a named query before execution, such as setting hints or properties, then it cannot use the cached results.

The query results cache does not pick up committed changes from the application as the object cache does. It should only be used to cache read-only objects, or should use an invalidation policy to avoid caching stale results. Committed changes to the objects in the result set will still be picked up, by changes that affect the results set (such as new or changed objects that should be added/removed from the result set) will not be picked up.

The query results cache supports a fixed size, cache type, and invalidation options.

The query results cache is configured through query hints.

Query Results Cache Query Hints
Hint Description Default Required?
eclipselink.cache.coordination.protocol Enable cache coordination using the communication protocol:
  • rmi - Use Java RMI to broadcast changes.
  • rmi-iiop - Use Java RMI over CORBA IIOP to broadcast changes.
  • jms - Use the Java Messaging Service to broadcast changes.
  • jms-publishing - Allows an EJB MessageDrivenBean to be used to broadcast changes. The MDB must be configured separately.
  • <class-name> - The fully qualified class name of a custom implementation of a TransportManager.
no coordination Required
eclipselink.cache.coordination.channel Sets the channel for cache coordination. All persistence units using the same channel will be coordinated. EclipseLinkCommandChannel Required
Query results cache annotation example
...
@Entity
@NamedQuery(
  name="findAllEmployeesInCity",
  query="Select e from Employee e where e.address.city = :city",
  hints={
    @Hint(name="", value="")
  })
public class Employee {
  ...
}
Query results cache XML example
<?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">
            <hint name="" value=""/>
        </named-query>
        ...
    </entity>
</entity-mappings>
Query results cache query example
Query query = em.createNamedQuery("findAllEmployeesInCity");
query.setParameter("city", "Ottawa");
List<Employee> employees = query.getResultList();

Eclipselink-logo.gif
Version: 2.4 DRAFT
Other versions...

Back to the top