@Index annotations are not allowed for this location

When trying to use the @Index annotation from javax.persistence Eclipse gives me this error.

I use it just before the java.util.Date field inside the class annotated with @Entity .

I used to use org.hibernate.annotations.Index in the same place, and everything was fine.

The problem started after I updated hibernate-core from 4.1.9.Final to 4.3.0.Beta3 and hibernate-commons-annotations from 4.0.1 to 4.0.2. He says that @Index deprecated and recommends javax.persistence alone.

All documents and examples I found put @Index in front of class members. What am I missing?

+24
java jpa hibernate-annotations
Jul 12 '13 at 17:12
source share
3 answers

JPA index annotations can only be used as part of another annotation such as @Table , @SecondaryTable , etc. (see the "See Also" section in Javadoc ):

 @Table(indexes = { @Index(...) }) 
+35
Jul 12 '13 at 17:17
source share

If you use Eclipselink , you can add this import to your class:

 import org.eclipse.persistence.annotations.Index; 

Then add @Index to your field:

 public class FooClass { @Index int field1; } 

or

 @Index(columnNames = {"field1", "field2"}) public class FooClass { int field1; int field2; } 
0
Apr 26 '14 at 2:28
source share

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) ...... 
0
Oct 19 '17 at 22:22
source share



All Articles