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/2.4/a cacheindex"

m
 
Line 1: Line 1:
{{EclipseLink_TLJPA
+
#REDIRECT [[EclipseLink/UserGuide/JPA/2.4/toc]]
|info=n
+
|toc=n
+
|category=JPA
+
|release=2.4.x
+
|title=TLJPA}}
+
<span class="metaname">    </span>
+
 
+
{| class="simple oac_no_warn" width="100%"
+
| align="left" valign="top" | 
+
| width="185" align="right" valign="bottom" |
+
{| class="simple oac_no_warn" width="100%"
+
|
+
| align="center" valign="top" |
+
[[Image:Elug_Magnifier.png|Search]][http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
+
| align="center" valign="top" |
+
&nbsp;&nbsp;&nbsp;[[Image:Elug_guide_icon.png|Contents]][[EclipseLink/UserGuide/JPA/2.4/toc| Contents]]
+
|}
+
|}
+
 
+
----
+
 
+
{| width="165"
+
| align="center" |
+
[[EclipseLink/UserGuide/JPA/2.4/a_cache| Previous ]]<span class="previouslink">[[Image:Elug_previous_icon.png|Previous]]</span>
+
| align="center" |
+
[[EclipseLink/UserGuide/JPA/2.4/a_cacheindexes| Next ]][[Image:Elug_next_icon.png|Next]]
+
|
+
|}
+
 
+
[[Image:Elug_draft_icon.png|Warning]]Beta Draft: 2012-06-18
+
 
+
<span id="CEGFEJCH"></span>
+
 
+
----
+
 
+
==@CacheIndex==
+
 
+
Use @CacheIndex to define a cached index. Cache indexes are used only when caching is enabled.
+
 
+
<span id="sthref40"></span>
+
 
+
''' '''
+
 
+
===Annotation Elements===
+
 
+
[[#BABFJHIC|Table 2-5]] describes this annotation's elements.
+
 
+
<span id="sthref41"></span><span id="BABFJHIC"></span>
+
 
+
'''''Table 2-5 @CacheIndex Annotation Elements'''''
+
 
+
{| class="HRuleFormalWide" dir="ltr" title="@CacheIndex Annotation Elements" summary="This table describes the list of attributes for this annotation." width="100%" border="1" frame="hsides" rules="rows" cellpadding="3" frame="hsides" rules="rows"
+
|- align="left" valign="top"
+
! id="r1c1-t8" align="left" valign="bottom" | '''Annotation Element'''
+
! id="r1c2-t8" align="left" valign="bottom" | '''Description'''
+
! id="r1c3-t8" align="left" valign="bottom" | '''Default'''
+
|- align="left" valign="top"
+
| id="r2c1-t8" headers="r1c1-t8" align="left" |
+
<code>columnNames</code>
+
| headers="r2c1-t8 r1c2-t8" align="left" |
+
(Optional) The set of columns on which to define the index. Not required when annotated on a field/method.
+
| headers="r2c1-t8 r1c3-t8" align="left" | <br />
+
|- align="left" valign="top"
+
| id="r3c1-t8" headers="r1c1-t8" align="left" |
+
<code>updateable</code>
+
| headers="r3c1-t8 r1c2-t8" align="left" |
+
(Optional) Specify if the indexed field is updateable.
+
 
+
If <code>true</code>, the object will be re-indexed on each update or refresh.
+
| headers="r3c1-t8 r1c3-t8" align="left" |
+
true
+
|}
+
 
+
<br />
+
 
+
<span id="sthref42"></span>
+
 
+
''' '''
+
 
+
===Usage===
+
 
+
A cache index allows <code>singleResult</code> queries to obtain a cache hit when querying on the indexed fields. A <code>resultList</code> query cannot obtain cache hits, as it is unknown if all of the objects are in memory, (unless the cache usage query hint is used).
+
 
+
The index should be unique. If it is not, the first indexed object will be returned.
+
 
+
You can use <code>@CacheIndex</code> on an Entity class or on an attribute. The column is defaulted when defined on a attribute.
+
 
+
<span id="sthref43"></span>
+
 
+
''' '''
+
 
+
===Examples===
+
 
+
[[#BABEECHH|Example 2-13]] shows an example of using the <code>@CacheIndex</code> annotation.
+
 
+
<span id="BABEECHH"></span>
+
 
+
'''''Example 2-13 Using @CacheIndex Annotation'''''
+
 
+
+
@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;
+
}
+
 
+
[[#BABIHBCC|Example 2-14]] shows an example of using the <code>&lt;cache-index&gt;</code> XML element in the <code>eclipselink-orm.xml</code> file.
+
 
+
<span id="BABIHBCC"></span>
+
 
+
'''''Example 2-14 Using &lt;cache-index&gt; XML'''''
+
 
+
+
&lt;?xml version="1.0"?&gt;
+
&lt;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"&gt;
+
    &lt;entity name="Employee" class="org.acme.Employee" access="FIELD"&gt;
+
        &lt;cache-index updateable="true"&gt;
+
            &lt;column-name&gt;F_NAME&lt;/column-name&gt;
+
            &lt;column-name&gt;L_NAME&lt;/column-name&gt;
+
        &lt;/cache-index&gt;
+
        &lt;attributes&gt;
+
            &lt;id name="id"/&gt;
+
            &lt;basic name="ssn"&gt;
+
                &lt;cache-index/&gt;
+
            &lt;/basic&gt;
+
            &lt;basic name="firstName"&gt;
+
                &lt;column name="F_NAME"/&gt;
+
            &lt;/basic&gt;
+
            &lt;basic name="lastName"&gt;
+
                &lt;column name="L_NAME"/&gt;
+
            &lt;/basic&gt;
+
        &lt;/attributes&gt;
+
    &lt;/entity&gt;
+
&lt;/entity-mappings&gt;
+
 
+
[[#BABBIAGH|Example 2-15]] shows an example query using a cache index.
+
 
+
<span id="BABBIAGH"></span>
+
 
+
'''''Example 2-15 Caching an Index Query'''''
+
 
+
+
Query query = em.createQuery("Select e from Employee e where e.firstName = :firstName and e.lastName = :lastName");
+
query.setParameter("firstName", "Bob");
+
query.setParameter("lastName", "Smith");
+
Employee employee = (Employee)query.getSingleResult();
+
 
+
<span id="sthref44"></span>
+
 
+
''' '''
+
 
+
===See Also===
+
 
+
For more information, see:
+
 
+
* [[EclipseLink/UserGuide/JPA/2.4/a_cache|"@Cache"]]
+
* "Cache Indexes" <code>http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Indexes</code>
+
 
+
<span id="footerspace"> </span>
+
 
+
----
+
 
+
{| class="simple oac_no_warn" width="100%"
+
|-
+
| valign="bottom" |
+
{| width="165"
+
|-
+
|
+
| align="center" |
+
[[EclipseLink/UserGuide/JPA/2.4/a_cache| Previous ]]<span class="previouslink">[[Image:Elug_previous_icon.png|Previous]]</span>
+
| align="center" |
+
[[EclipseLink/UserGuide/JPA/2.4/a_cacheindexes| Next ]][[Image:Elug_next_icon.png|Next]]
+
|}
+
| width="34%" align="center" |
+
[[Image:Eclipselink-logo.gif|150px|EclispeLink]]<br />[[Image:Elug_home_icon.png|EclipseLink logo]] [http://www.eclipse.org/eclipselink/ EclipseLink Home] • [[Image:Elug_pdf.png|PDF]] PDF (coming soon)<br />
+
| align="right" valign="bottom" |
+
{| class="simple oac_no_warn" width="225"
+
|
+
| align="center" valign="top" |
+
[[Image:Elug_Magnifier.png|Search]][http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
+
| align="center" valign="top" |
+
&nbsp;&nbsp;&nbsp;[[Image:Elug_guide_icon.png|Contents]][[EclipseLink/UserGuide/JPA/2.4/toc| Contents]]
+
|}
+
|}
+

Latest revision as of 12:22, 29 June 2012

Back to the top