Difference between revisions of "EclipseLink/UserGuide/JPA/Advanced JPA Development/Schema Generation/Index"
m |
|||
Line 3: | Line 3: | ||
|toc=n | |toc=n | ||
|eclipselink=y | |eclipselink=y | ||
− | |eclipselinktype=JPA | + | |eclipselinktype=JPA |
− | = | + | |api=y |
+ | |apis= | ||
+ | * [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/annotations/Index.html Index] | ||
+ | * [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/tools/schemaframework/IndexDefinition.html IndexDefinition] | ||
+ | }} | ||
− | Use the @Index annotation in code or the <index> element in orm.xml to | + | |
+ | =@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 and to have EclipseLink's DDL generator generate it. | ||
+ | |||
+ | 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 name of the index defaults to _<column>_INDEX, but a name should be provided. | ||
+ | |||
+ | An IndexDefinition in the schema framework allows defining, creating, and dropping indexes using code. | ||
+ | |||
+ | 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 = | ||
+ | * orm.xml | ||
+ | <source lang="xml"> | ||
+ | <index name="EMP_NAME_INDEX" table="EMPLOYEE" unique="true"> | ||
+ | <column>F_NAME</column> | ||
+ | <column>L_NAME</column> | ||
+ | </index> | ||
+ | </source> | ||
{{EclipseLink_JPA | {{EclipseLink_JPA | ||
|previous =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation/CascadeOnDelete|@CascadeOnDelete]] | |previous =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation/CascadeOnDelete|@CascadeOnDelete]] | ||
|up =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation|Schema Generation]] | |up =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation|Schema Generation]] | ||
− | |next =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/ | + | |next =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance|Performance]] |
|version=2.2.0 DRAFT}} | |version=2.2.0 DRAFT}} |
Revision as of 14:17, 26 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 and to have EclipseLink's DDL generator generate it.
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 name of the index defaults to _<column>_INDEX, but a name should be provided.
An IndexDefinition in the schema framework allows defining, creating, and dropping indexes using code.
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
- orm.xml
<index name="EMP_NAME_INDEX" table="EMPLOYEE" unique="true"> <column>F_NAME</column> <column>L_NAME</column> </index>