@Index注释如何在JPA 2.1中起作用?

时间:2013-11-02 22:25:57

标签: java hibernate jpa

我正在尝试测试自2.1以来可用的JPA的@Index注释。但是我找不到文档如何使用它。

当我尝试时:

@Index(columnList = "firstName")
private String firstName;

..然后Eclipse说:“这个位置不允许注释@Index”

有谁知道如何使用它?或者找到了它的文档? : - )

感谢您的任何建议!

1 个答案:

答案 0 :(得分:19)

我已经使用了hibernate @Index注释,但没有任何问题,但看起来JPA @Index注释在可以使用的地方更严格。摘自上一个问题 - The annotation @Index is disallowed for this location

  

JPA索引注释只能用作@Table@SecondaryTable等其他注释的一部分。

@Table(indexes = { @Index(...) })