When trying to use the @Index annotation from javax.persistence, Eclipse gives me this error.
I\'m using it right before a java.util.
If you use Eclipselink you can add this import to your class:
import org.eclipse.persistence.annotations.Index;
Then add your @Index to your field like this:
public class FooClass {
@Index
int field1;
}
or
@Index(columnNames = {"field1", "field2"})
public class FooClass {
int field1;
int field2;
}
The JPA Index annotation can only be used as part of another annotation like @Table, @SecondaryTable, etc. (see the See Also section in the javadoc):
@Table(indexes = { @Index(...) })
See here: https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#annotations-jpa-index
use this:
@Table
.......,indexes = @Index(columnList = ("COLUMN_NAME"),name="CUSTOM NAME AT INDEX",unique=false)
......