Difference between revisions of "EclipseLink/UserGuide/JPA/Advanced JPA Development/Schema Generation/Index"
Line 9: | Line 9: | ||
* [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/tools/schemaframework/IndexDefinition.html IndexDefinition] | * [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/tools/schemaframework/IndexDefinition.html IndexDefinition] | ||
}} | }} | ||
− | + | <source lang="java"> | |
+ | </source> | ||
=@Index Annotation and <index> XML= | =@Index Annotation and <index> XML= | ||
Line 16: | Line 17: | ||
An index is a database structure defined for a table, to improve query and look-up performance for a set of columns. | 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 desciptor to create an index on a table and to | + | Use the @Index annotation in code or the <index> element in the orm.xml desciptor to create an index on a table. |
+ | |||
+ | {{EclipseLink_AttributeTable | ||
+ | |caption=@Index Attributes | ||
+ | |content= | ||
+ | <tr> | ||
+ | <td>'''<tt>catalog</tt>'''</td> | ||
+ | <td>The catalog of the INDEX.</td> | ||
+ | <td>?</td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>columnNames</tt>'''</td> | ||
+ | <td>Specify the set of columns to define the index on. </td> | ||
+ | <td>For an Entity , the table. For an attribute, the table and column.</td> | ||
+ | <td>Not required when annotated on a field or method.</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>name</tt>'''</td> | ||
+ | <td>The name of the INDEX.</td> | ||
+ | <td><tt>_<column>_INDEX</tt> (but a name should be provided)</td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>schema</tt>'''</td> | ||
+ | <td>The schema of the INDEX.</td> | ||
+ | <td><tt>?</tt></td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>table</tt>'''</td> | ||
+ | <td>The table to define the index on, defaults to entities primary table.</td> | ||
+ | <td>The entity's primary table.</td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>'''<tt>unique</tt>'''</td> | ||
+ | <td>?</td> | ||
+ | <td><tt>false</tt></td> | ||
+ | <td>No</td> | ||
+ | </tr> | ||
+ | }} | ||
+ | |||
An index can be defined on an Entity class or on an attribute: | An index can be defined on an Entity class or on an attribute: | ||
* For the Entity it must define a set of columns to index. The table is defaulted. | * For the Entity it must define a set of columns to index. The table is defaulted. | ||
* For an attribute, the table and column are defaulted. | * For an attribute, the table and column are defaulted. | ||
− | |||
− | |||
The @Index annotation creates an IndexDefinition and stores it on the descriptor's DatabaseTable. | The @Index annotation creates an IndexDefinition and stores it on the descriptor's DatabaseTable. | ||
Line 33: | Line 74: | ||
= Configuration File = | = Configuration File = | ||
− | + | ||
+ | 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 11:24, 31 January 2011
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
@Index Annotation and <index> XML
This section is in progress...
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 desciptor to create an index on a table.
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 | ? | false | No |
An index can be defined on an Entity class or on an attribute:
- For the Entity it must define a set of columns to index. The table is defaulted.
- For an attribute, the table and column are defaulted.
The @Index annotation creates an IndexDefinition and stores it on the descriptor's DatabaseTable.
During default schema generation the DefaultSchemaGenerator adds the IndexDefinition to the TableDefinition to be created.
The IndexDefinition is used to create indexes for primary key and unique constraints. Support for indexes is defined in the platform. By default a platform is assumed to support indexes. MySQL requires special drop syntax to include the table name in the drop statement.
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>