|
|
(6 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{EclipseLink_TLJPA
| + | #REDIRECT [[EclipseLink/UserGuide/JPA/2.4/toc]] |
− | |info=n
| + | |
− | |toc=n
| + | |
− | |category=JPA
| + | |
− | |release=2.4.x
| + | |
− | title=}}
| + | |
− | <span class="metaname"> </span>
| + | |
− | | + | |
− | {| class="simple oac_no_warn" width="100%"
| + | |
− | | align="left" valign="top" |
| + | |
− | | width="144" align="right" valign="bottom" |
| + | |
− | {| class="simple oac_no_warn" width="100%"
| + | |
− | |
| + | |
− | | align="center" valign="top" |
| + | |
− | [http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
| + | |
− | | align="center" valign="top" |
| + | |
− | [[EclipseLink/UserGuide/JPA/toc| Contents]] | + | |
− | |}
| + | |
− | |}
| + | |
− | | + | |
− | ----
| + | |
− | | + | |
− | {| width="150"
| + | |
− | | align="center" |
| + | |
− | [[EclipseLink/UserGuide/JPA/a_cache|<- Previous]]
| + | |
− | | align="center" |
| + | |
− | [[EclipseLink/UserGuide/JPA/a_cacheindexes|Next ->]]
| + | |
− | |
| + | |
− | |}
| + | |
− | | + | |
− | <span id="CEGFEJCH"></span>
| + | |
− | | + | |
− | ----
| + | |
− | | + | |
− | ==@CacheIndex==
| + | |
− | | + | |
− | Use @CacheIndex to define a cached index. Cache indexes are used only when caching is enabled.
| + | |
− | | + | |
− | <span id="sthref43"></span>
| + | |
− | | + | |
− | ''' '''
| + | |
− | | + | |
− | ===Annotation Elements===
| + | |
− | | + | |
− | [[#BABFJHIC|Table 2-1]] describes this annotation's elements.
| + | |
− | | + | |
− | <span id="sthref44"></span><span id="BABFJHIC"></span>
| + | |
− | | + | |
− | '''''Table 2-1 @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-t2" align="left" valign="bottom" | '''Annotation Element'''
| + | |
− | ! id="r1c2-t2" align="left" valign="bottom" | '''Description'''
| + | |
− | ! id="r1c3-t2" align="left" valign="bottom" | '''Default'''
| + | |
− | |- align="left" valign="top"
| + | |
− | | id="r2c1-t2" headers="r1c1-t2" align="left" |
| + | |
− | <code>columnNames</code>
| + | |
− | | headers="r2c1-t2 r1c2-t2" align="left" |
| + | |
− | (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 />
| + | |
− | |- align="left" valign="top"
| + | |
− | | id="r3c1-t2" headers="r1c1-t2" align="left" |
| + | |
− | <code>updateable</code>
| + | |
− | | headers="r3c1-t2 r1c2-t2" 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-t2 r1c3-t2" align="left" |
| + | |
− | true
| + | |
− | |}
| + | |
− | | + | |
− | <br />
| + | |
− | | + | |
− | <span id="sthref45"></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="sthref46"></span>
| + | |
− | | + | |
− | ''' '''
| + | |
− | | + | |
− | ===Examples===
| + | |
− | | + | |
− | [[#BABEECHH|Example 2-1]] shows an example of using the <code>@CacheIndex</code> annotation.
| + | |
− | | + | |
− | <span id="BABEECHH"></span>
| + | |
− | | + | |
− | '''''Example 2-1 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-2]] shows an example of using the <code><cache-index></code> XML element in the <code>eclipselink-orm.xml</code> file.
| + | |
− | | + | |
− | <span id="BABIHBCC"></span>
| + | |
− | | + | |
− | '''''Example 2-2 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>
| + | |
− | | + | |
− | [[#BABBIAGH|Example 2-3]] shows an example query using a cache index.
| + | |
− | | + | |
− | <span id="BABBIAGH"></span>
| + | |
− | | + | |
− | '''''Example 2-3 Cache 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="sthref47"></span>
| + | |
− | | + | |
− | ''' '''
| + | |
− | | + | |
− | ===See Also===
| + | |
− | | + | |
− | For more information, see:
| + | |
− | | + | |
− | * [[EclipseLink/UserGuide/JPA/a_cache|"@Cache"]]
| + | |
− | * "Cache Indexes" <code>http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Indexes</code>
| + | |
− | | + | |
− | ----
| + | |
− | | + | |
− | {| class="simple oac_no_warn" width="100%"
| + | |
− | |-
| + | |
− | | valign="bottom" |
| + | |
− | {| width="150"
| + | |
− | |-
| + | |
− | |
| + | |
− | | align="center" |
| + | |
− | [[EclipseLink/UserGuide/JPA/a_cache|<- Previous]]
| + | |
− | | align="center" |
| + | |
− | [[EclipseLink/UserGuide/JPA/a_cacheindexes|Next ->]]
| + | |
− | |}
| + | |
− | | width="34%" align="center" |
| + | |
− | [[Image:Eclipselink-logo.gif|150px|EclispeLink]]<br />[http://wiki.eclipse.org/EclipseLink EclipseLink Home]<br />
| + | |
− | | align="right" valign="bottom" |
| + | |
− | {| class="simple oac_no_warn" width="225"
| + | |
− | |
| + | |
− | | align="center" valign="top" |
| + | |
− | [http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
| + | |
− | | align="center" valign="top" |
| + | |
− | [[EclipseLink/UserGuide/JPA/toc| Contents]]
| + | |
− | |}
| + | |
− | |}
| + | |