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/Advanced JPA Development/Schema Generation/Index"

m
Line 82: Line 82:
 
</source>
 
</source>
  
== Defining an Index in orm.xml ==
+
== Defining an Index in eclipselink-orm.xml ==
 +
 
 +
Create an index in <tt>eclipselink-orm.xml</tt> using <tt><index></tt>, as shown in the following example. Define columns using the <tt><column></tt> subelement to define columns. All the attributes supported in the @Index annotation are also supported in the <tt><index></tt> element.
  
Create an index in <tt>orm.xml</tt> using <tt><index></tt>, as follows:
 
 
<source lang="xml">
 
<source lang="xml">
 
<index name="EMP_NAME_INDEX" table="EMPLOYEE" unique="true">
 
<index name="EMP_NAME_INDEX" table="EMPLOYEE" unique="true">

Revision as of 15:16, 16 February 2011

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source


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

@Index Annotation

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 creation is database specific, some databases may not support indexes. Most databases auto index primary key and foriegn key columns. Some databases support advanced index DDL options. To create more advanced index DDL, a DDL script or native query can be used.

Index Attributes
Attribute Description Default Required?
catalog The catalog of the INDEX. Default catalog 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. <table>_<column>_INDEX (but a name should be provided) No
schema The schema of the INDEX. Default schema 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


@Index Annotation Example

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

Defining an Index in eclipselink-orm.xml

Create an index in eclipselink-orm.xml using <index>, as shown in the following example. Define columns using the <column> subelement to define columns. All the attributes supported in the @Index annotation are also supported in the <index> element.

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

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

Back to the top