Jump to: navigation, search

EclipseLink/Examples/JPA/Indexes

< EclipseLink‎ | Examples‎ | JPA
Revision as of 12:24, 24 January 2011 by James.sutherland.oracle.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


EclipseLink (as of 2.2) provides a way to have a database INDEX generated when EclipseLink is used to generate the database. An index is used in a database to optimize queries that use that column to provide optimal look-up and avoid table scans. Different databases have different levels of index support, EclipseLink supports the creation of basic indexes on databases that support them. EclipseLink supports index creation using its @Index annotation or <index> xml element. The @Index has a name and a set of columns.

Example Index

The firstName and lastName are indexed.

@Entity
@Index(name="EMP_NAME_INDEX", columns={@Column(name="F_NAME"),@Column(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;
    ...
}

This produces the SQL,

CREATE INDEX 
</sql>