Java @Index 注释在 JPA 2.1 中如何工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19747594/
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
How does the @Index annotation work in JPA 2.1?
提问by Crayl
I'am trying to test JPA's @Index annotation which is avaliable since 2.1. But I can't find the documention how to use it.
我正在尝试测试自 2.1 以来可用的 JPA 的 @Index 注释。但是我找不到如何使用它的文档。
When I'am trying:
当我尝试:
@Index(columnList = "firstName")
private String firstName;
.. then Eclipse says: "The annotation @Index is disallowed for this location"
..然后Eclipse说:“这个位置不允许使用@Index注释”
Does anyone know how to use it? Or has found the documentation for it? :-)
有谁知道如何使用它?或者已经找到了它的文档?:-)
Thanks for any suggestions!
感谢您的任何建议!
采纳答案by John Farrelly
I've used the hibernate @Index
annotation just as you have with no issues, but it appears that the JPA @Index
annotation is stricter on where it can be used. Taken from a previous question - The annotation @Index is disallowed for this location:
我已经@Index
像您一样使用了 hibernate注释,没有任何问题,但似乎 JPA@Index
注释在可以使用的地方更严格。取自上一个问题 -此位置不允许使用 @Index 注释:
The JPA Index annotation can only be used as part of another annotation like
@Table
,@SecondaryTable
, etc.
在JPA指数注释只能被用作另一个注释的状部分
@Table
,@SecondaryTable
等等。
@Table(indexes = { @Index(...) })