Indexes

JPA 2.1 introduces the @Index annotation. It lets you automatically create indexes on the database. Here is a sample for the Book entity:

@Table(name = "book",   indexes = {      @Index(name = "index_title", columnList = "title", unique = true),      @Index(name = "index_publisher", columnList = "publisher", unique = false) })public class Book {   private String title;   private String publisher;...}

In your database, in the table book, you will see the two indexes called index_title and index_publisher tied respectively to the fields title and publisher of the Book entity. The unique field of the annotation indicates that the index enforces the constraint that you cannot have two equal values in that column in two different rows. Here are the indexes ...

Get Mastering Java EE Development with WildFly now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.