Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/2.4/a cacheindex"

m (Examples)
m
Line 4: Line 4:
 
|category=JPA
 
|category=JPA
 
|release=2.4.x
 
|release=2.4.x
|title=}}
+
|title=TLJPA}}
 
<span class="metaname">    </span>
 
<span class="metaname">    </span>
  
 
{| class="simple oac_no_warn" width="100%"
 
{| class="simple oac_no_warn" width="100%"
 
| align="left" valign="top" |   
 
| align="left" valign="top" |   
| width="144" align="right" valign="bottom" |
+
| width="185" align="right" valign="bottom" |
 
{| class="simple oac_no_warn" width="100%"
 
{| class="simple oac_no_warn" width="100%"
 
|
 
|
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
+
[[Image:Elug_Magnifier.png|Search]][http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[[EclipseLink/UserGuide/JPA/toc| Contents]]
+
&nbsp;&nbsp;&nbsp;[[Image:Elug_guide_icon.png|Contents]][[EclipseLink/UserGuide/JPA/2.4/toc| Contents]]
 
|}
 
|}
 
|}
 
|}
Line 21: Line 21:
 
----
 
----
  
{| width="150"
+
{| width="165"
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_cache|&lt;- Previous]]
+
[[EclipseLink/UserGuide/JPA/2.4/a_cache| Previous ]]<span class="previouslink">[[Image:Elug_previous_icon.png|Previous]]</span>
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_cacheindexes|Next -&gt;]]
+
[[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>
 
<span id="CEGFEJCH"></span>
Line 37: Line 39:
 
Use @CacheIndex to define a cached index. Cache indexes are used only when caching is enabled.
 
Use @CacheIndex to define a cached index. Cache indexes are used only when caching is enabled.
  
<span id="sthref43"></span>
+
<span id="sthref40"></span>
  
 
''' '''
 
''' '''
Line 43: Line 45:
 
===Annotation Elements===
 
===Annotation Elements===
  
[[#BABFJHIC|Table 2-1]] describes this annotation's elements.
+
[[#BABFJHIC|Table 2-5]] describes this annotation's elements.
  
<span id="sthref44"></span><span id="BABFJHIC"></span>
+
<span id="sthref41"></span><span id="BABFJHIC"></span>
  
'''''Table 2-1 @CacheIndex Annotation Elements'''''
+
'''''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"
 
{| 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"
 
|- align="left" valign="top"
! id="r1c1-t2" align="left" valign="bottom" | '''Annotation Element'''
+
! id="r1c1-t8" align="left" valign="bottom" | '''Annotation Element'''
! id="r1c2-t2" align="left" valign="bottom" | '''Description'''
+
! id="r1c2-t8" align="left" valign="bottom" | '''Description'''
! id="r1c3-t2" align="left" valign="bottom" | '''Default'''
+
! id="r1c3-t8" align="left" valign="bottom" | '''Default'''
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r2c1-t2" headers="r1c1-t2" align="left" |
+
| id="r2c1-t8" headers="r1c1-t8" align="left" |
 
<code>columnNames</code>
 
<code>columnNames</code>
| headers="r2c1-t2 r1c2-t2" align="left" |
+
| 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.
 
(Optional) The set of columns on which to define the index. Not required when annotated on a field/method.
| headers="r2c1-t2 r1c3-t2" align="left" | <br />
+
| headers="r2c1-t8 r1c3-t8" align="left" | <br />
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r3c1-t2" headers="r1c1-t2" align="left" |
+
| id="r3c1-t8" headers="r1c1-t8" align="left" |
 
<code>updateable</code>
 
<code>updateable</code>
| headers="r3c1-t2 r1c2-t2" align="left" |
+
| headers="r3c1-t8 r1c2-t8" align="left" |
 
(Optional) Specify if the indexed field is updateable.
 
(Optional) Specify if the indexed field is updateable.
  
 
If <code>true</code>, the object will be re-indexed on each update or refresh.
 
If <code>true</code>, the object will be re-indexed on each update or refresh.
| headers="r3c1-t2 r1c3-t2" align="left" |
+
| headers="r3c1-t8 r1c3-t8" align="left" |
 
true
 
true
 
|}
 
|}
Line 73: Line 75:
 
<br />
 
<br />
  
<span id="sthref45"></span>
+
<span id="sthref42"></span>
  
 
''' '''
 
''' '''
Line 85: Line 87:
 
You can use <code>@CacheIndex</code> on an Entity class or on an attribute. The column is defaulted when defined on a attribute.
 
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="sthref46"></span>
+
<span id="sthref43"></span>
  
 
''' '''
 
''' '''
Line 91: Line 93:
 
===Examples===
 
===Examples===
  
[[#BABEECHH|Example 2-1]] shows an example of using the <code>@CacheIndex</code> annotation.
+
[[#BABEECHH|Example 2-13]] shows an example of using the <code>@CacheIndex</code> annotation.
  
 
<span id="BABEECHH"></span>
 
<span id="BABEECHH"></span>
  
'''''Example 2-1 Using @CacheIndex Annotation'''''
+
'''''Example 2-13 Using @CacheIndex Annotation'''''
 
+
  
 +
 
  @Entity
 
  @Entity
 
  @CacheIndex(columnNames={"F_NAME", "L_NAME"}, updateable=true)
 
  @CacheIndex(columnNames={"F_NAME", "L_NAME"}, updateable=true)
Line 110: Line 112:
 
   private String lastName;
 
   private String lastName;
 
  }
 
  }
[[#BABIHBCC|Example 2-2]] shows an example of using the <code>&lt;cache-index&gt;</code> XML element in the <code>eclipselink-orm.xml</code> file.
+
 
 +
[[#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>
 
<span id="BABIHBCC"></span>
  
'''''Example 2-2 Using &lt;cache-index&gt; XML'''''
+
'''''Example 2-14 Using &lt;cache-index&gt; XML'''''
  
 +
 
  &lt;?xml version="1.0"?&gt;
 
  &lt;?xml version="1.0"?&gt;
 
  &lt;entity-mappings
 
  &lt;entity-mappings
Line 142: Line 146:
 
  &lt;/entity-mappings&gt;
 
  &lt;/entity-mappings&gt;
  
[[#BABBIAGH|Example 2-3]] shows an example query using a cache index.
+
[[#BABBIAGH|Example 2-15]] shows an example query using a cache index.
  
 
<span id="BABBIAGH"></span>
 
<span id="BABBIAGH"></span>
  
'''''Example 2-3 Cache Index Query'''''
+
'''''Example 2-15 Caching an Index Query'''''
  
 
   
 
   
Line 154: Line 158:
 
  Employee employee = (Employee)query.getSingleResult();
 
  Employee employee = (Employee)query.getSingleResult();
  
<span id="sthref47"></span>
+
<span id="sthref44"></span>
  
 
''' '''
 
''' '''
Line 162: Line 166:
 
For more information, see:
 
For more information, see:
  
* [[EclipseLink/UserGuide/JPA/a_cache|"@Cache"]]
+
* [[EclipseLink/UserGuide/JPA/2.4/a_cache|"@Cache"]]
 
* "Cache Indexes" <code>http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Indexes</code>
 
* "Cache Indexes" <code>http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Indexes</code>
 +
 +
<span id="footerspace"> </span>
  
 
----
 
----
Line 170: Line 176:
 
|-
 
|-
 
| valign="bottom" |
 
| valign="bottom" |
{| width="150"
+
{| width="165"
 
|-
 
|-
 
|
 
|
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_cache|&lt;- Previous]]
+
[[EclipseLink/UserGuide/JPA/2.4/a_cache| Previous ]]<span class="previouslink">[[Image:Elug_previous_icon.png|Previous]]</span>
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_cacheindexes|Next -&gt;]]
+
[[EclipseLink/UserGuide/JPA/2.4/a_cacheindexes| Next ]][[Image:Elug_next_icon.png|Next]]
 
|}
 
|}
 
| width="34%" align="center" |
 
| width="34%" align="center" |
[[Image:Eclipselink-logo.gif|150px|EclispeLink]]<br />[http://wiki.eclipse.org/EclipseLink EclipseLink Home]<br />
+
[[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" |
 
| align="right" valign="bottom" |
 
{| class="simple oac_no_warn" width="225"
 
{| class="simple oac_no_warn" width="225"
 
|
 
|
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
+
[[Image:Elug_Magnifier.png|Search]][http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[[EclipseLink/UserGuide/JPA/toc| Contents]]
+
&nbsp;&nbsp;&nbsp;[[Image:Elug_guide_icon.png|Contents]][[EclipseLink/UserGuide/JPA/2.4/toc| Contents]]
 
|}
 
|}
 
|}
 
|}

Revision as of 14:16, 19 June 2012


Java Persistence API (JPA) Extensions Reference for EclipseLink, 2.4.x

SearchSearch

   Contents Contents


Previous Previous

Next Next

WarningBeta Draft: 2012-06-18


@CacheIndex

Use @CacheIndex to define a cached index. Cache indexes are used only when caching is enabled.

Annotation Elements

Table 2-5 describes this annotation's elements.

Table 2-5 @CacheIndex Annotation Elements

Annotation Element Description Default

columnNames

(Optional) The set of columns on which to define the index. Not required when annotated on a field/method.


updateable

(Optional) Specify if the indexed field is updateable.

If true, the object will be re-indexed on each update or refresh.

true


Usage

A cache index allows singleResult queries to obtain a cache hit when querying on the indexed fields. A resultList 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 @CacheIndex on an Entity class or on an attribute. The column is defaulted when defined on a attribute.

Examples

Example 2-13 shows an example of using the @CacheIndex annotation.

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;
}

Example 2-14 shows an example of using the <cache-index> XML element in the eclipselink-orm.xml file.

Example 2-14 Using <cache-index> XML


<?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>

Example 2-15 shows an example query using a cache index.

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();

See Also

For more information, see:

 


Previous Previous

Next Next

EclispeLink
EclipseLink logo EclipseLink Home • PDF PDF (coming soon)

SearchSearch

   Contents Contents

Back to the top