O'Reilly logo

Mastering Java EE Development with WildFly by Luca Stancapiano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required