Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Advanced JPA Development/Schema Generation/Index"

Line 19: Line 19:
 
An index can be defined on an Entity or on an attribute. For the Entity it must define a set of columns to index.   
 
An index can be defined on an Entity or on an attribute. For the Entity it must define a set of columns to index.   
  
<source lang="java">
 
@Entity
 
@Index(name="EMP_NAME_INDEX", columns={"F_NAME","L_NAME"})
 
public class Employee{
 
    @Id
 
    private long id;
 
    @Index
 
    @Column(name="F_NAME")
 
    private String firstName;
 
    @Index
 
    @Column(name="L_NAME")
 
    private String lastName;
 
    ...
 
}
 
</source>
 
  
 
{{EclipseLink_AttributeTable
 
{{EclipseLink_AttributeTable
Line 76: Line 61:
 
}}
 
}}
  
= Configuration File =
+
== Configuration File ==
  
 
Create an index in <tt>orm.xml</tt> using <tt><index></tt>, as follows:
 
Create an index in <tt>orm.xml</tt> using <tt><index></tt>, as follows:
Line 84: Line 69:
 
     <column>L_NAME</column>
 
     <column>L_NAME</column>
 
</index>
 
</index>
 +
</source>
 +
 +
== Example ==
 +
=== Java ===
 +
<source lang="java">
 +
@Entity
 +
@Index(name="EMP_NAME_INDEX", columns={"F_NAME","L_NAME"})
 +
public class Employee{
 +
    @Id
 +
    private long id;
 +
    @Index
 +
    @Column(name="F_NAME")
 +
    private String firstName;
 +
    @Index
 +
    @Column(name="L_NAME")
 +
    private String lastName;
 +
    ...
 +
}
 
</source>
 
</source>
  

Revision as of 15:30, 1 February 2011

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source


@Index Annotation and <index> XML

>>>>>>THIS PAGE IS IN PROGRESS. PLEASE SEE DISCUSSION PAGE.<<<<<<

An index is a database structure defined for a table, to improve query and look-up performance for a set of columns. Use the @Index annotation in code or the <index> element in the orm.xml descriptor to create an index on a table.

An index can be defined on an Entity or on an attribute. For the Entity it must define a set of columns to index.


@Index Attributes
Attribute Description Default Required?
catalog The catalog of the INDEX. ? No
columnNames Specify the set of columns to define the index on. For an Entity , the table. For an attribute, the table and column. Not required when annotated on a field or method.
name The name of the INDEX. _<column>_INDEX (but a name should be provided) No
schema The schema of the INDEX. ? No
table The table to define the index on, defaults to entities primary table. The entity's primary table. No
unique Specify whether the index is unique or non-unique. false No

Configuration File

Create an index in orm.xml using <index>, as follows:

<index name="EMP_NAME_INDEX" table="EMPLOYEE" unique="true">
    <column>F_NAME</column>
    <column>L_NAME</column>
</index>

Example

Java

 
@Entity
@Index(name="EMP_NAME_INDEX", columns={"F_NAME","L_NAME"})
public class Employee{
    @Id
    private long id;
    @Index
    @Column(name="F_NAME")
    private String firstName;
    @Index
    @Column(name="L_NAME")
    private String lastName;
    ...
}

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