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.
EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Query Cache
< EclipseLink | UserGuide | JPA | Basic JPA Development | Caching
Revision as of 14:46, 28 May 2012 by Unnamed Poltroon (Talk) (New page: {{EclipseLink_UserGuide |info=y |toc=y |eclipselink=y |eclipselinktype=JPA |api=y |apis= *[http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/config/QueryHints.html Quer...)
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
Native API
Contents
Query Results Cache
By default in EclipseLink all queries that are not by Id, or not by cache indexed fields, will access the database. 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 cannot be used by default, as they can not assume that all of the objects are in the cache.
Query results cache annotation example
... @Entity @CacheIndex(columnNames={"F_NAME", "L_NAME"}, updateable=true) public class Employee { @Id private long id; @CacheIndex private String ssn; @Column(name="F_NAME") private String firstName; @Column(name="L_NAME") private String lastName; }
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"> <cache-index updateable="true"> <column-name>F_NAME</column-name> <column-name>L_NAME</column-name> </cache-index> <attributes> <id name="id"/> <basic name="ssn"> <cache-index/> </basic> <basic name="firstName"> <column name="F_NAME"/> </basic> <basic name="lastName"> <column name="L_NAME"/> </basic> </attributes> </entity> </entity-mappings>
Query results cache query example
Query query = em.createNamedQuery("findAllEmployeesInCity"); query.setParameter("city", "Ottawa"); List<Employee> employees = query.getResultList();