How to Annotate Index on a MappedSuperclass
I have a mapped superclass with two already indexed properties. now i want to create a group index over both properties. until now it worked with:
@MappedSuperclass
Class A {
@Index(name="pa")
int a;
@Index(name="pb")
int b;
}开发者_StackOverflow中文版
According to the hibernate documentation i could annotate my new index with @Table (hibernate annotation). but i dont know what to set for the required appliesTo parameter.
has anybody tried this successfully before?
From Hibernate Documentation:
@Table(appliesTo="tableName", indexes = { @Index(name="index1", columnNames={"column1", "column2"} ) } ) creates the defined indexes on the columns of table tableName. This can be applied on the primary table or any secondary table.
Update:
For the @MappedSuperclass you could try to use @Tables annotation
@Tables(value={@Table(appliesTo="table1", indexes={@Index(name="index1", columnNames={"column1", "column2"})}),
@Table(appliesTo="table2", indexes={@Index(name="index1", columnNames={"column1", "column2"})})})
But that seems rather tedious. Note that, @Index annotation has columnNames property, which allows you to specify more than one column. However, I'm not sure whether you should duplicate index definition for each field.
精彩评论