Java 此位置不允许使用批注@Index
当试图使用Java 此位置不允许使用批注@Index,java,jpa,hibernate-annotations,Java,Jpa,Hibernate Annotations,当试图使用javax.persistence中的@Index注释时,Eclipse给了我这个错误 我正是在java.util.Date字段前面使用它的,在一个用@Entity注释的类中 以前,我在同一个地方使用org.hibernate.annotations.Index,效果很好 问题是在我将hibernate core从4.1.9.Final升级到4.3.0.Beta3,并将hibernate commons注释从4.0.1升级到4.0.2之后出现的。它说@Index已被弃用,并建议使用ja
javax.persistence
中的@Index
注释时,Eclipse给了我这个错误
我正是在java.util.Date
字段前面使用它的,在一个用@Entity
注释的类中
以前,我在同一个地方使用org.hibernate.annotations.Index
,效果很好
问题是在我将hibernate core从4.1.9.Final升级到4.3.0.Beta3,并将hibernate commons注释从4.0.1升级到4.0.2之后出现的。它说@Index
已被弃用,并建议使用javax.persistence
one
我找到的所有文档和示例都将
@Index
放在类成员前面。我缺少什么?JPA索引注释只能用作另一个注释的一部分,如@Table
、@SecondaryTable
等(请参见中的另一部分):
如果使用
Eclipselink
可以将此导入添加到类中:
import org.eclipse.persistence.annotations.Index;
然后将@Index
添加到字段中,如下所示:
public class FooClass {
@Index
int field1;
}
或
请看这里:
使用以下命令:
@Table
.......,indexes = @Index(columnList = ("COLUMN_NAME"),name="CUSTOM NAME AT INDEX",unique=false)
......
我认为问题在于JPA2.1@Index注释,而不是专有注释。
@Index(columnNames = {"field1", "field2"})
public class FooClass {
int field1;
int field2;
}
@Table
.......,indexes = @Index(columnList = ("COLUMN_NAME"),name="CUSTOM NAME AT INDEX",unique=false)
......