java 此位置不允许使用注释 @Index
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17620405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The annotation @Index is disallowed for this location
提问by Vituel
When trying to use the @Index
annotation from javax.persistence
, Eclipse gives me this error.
尝试使用 中的@Index
注释时javax.persistence
,Eclipse 给了我这个错误。
I'm using it right before a java.util.Date
field, inside a class annotated with @Entity
.
我在一个java.util.Date
字段之前使用它,在一个用@Entity
.
Before, I was using org.hibernate.annotations.Index
in the exact same place and it was fine.
之前,我org.hibernate.annotations.Index
在完全相同的地方使用,它很好。
The problem started after I've upgraded hibernate-corefrom 4.1.9.Finalto 4.3.0.Beta3and hibernate-commons-annotations from 4.0.1to 4.0.2. It says @Index
is deprecated and recommends the javax.persistence
one.
在我将hibernate-core从4.1.9.Final升级到4.3.0.Beta3并将hibernate-commons-annotation从4.0.1升级到4.0.2之后,问题就开始了。它说不@Index
推荐使用并推荐javax.persistence
一个。
All docs and examples I've found put @Index
before class members. What am I missing?
我发现的所有文档和示例都放在@Index
班级成员面前。我错过了什么?
回答by JB Nizet
回答by Vituel
见这里: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)
......
回答by Joe Almore
If you use Eclipselink
you can add this import to your class:
如果您使用,Eclipselink
您可以将此导入添加到您的课程中:
import org.eclipse.persistence.annotations.Index;
Then add your @Index
to your field like this:
然后@Index
像这样将您的添加到您的字段中:
public class FooClass {
@Index
int field1;
}
or
或者
@Index(columnNames = {"field1", "field2"})
public class FooClass {
int field1;
int field2;
}