How to create an index with JPA/hibernate and use fields from MappedSuperClass together with fields from concrete entity
If you are using JPA 2.1
then you can use class annotation @Table
with its attribute indexes
@Table(indexes = { @Index(name = "IDX_MYIDX1", columnList = "id,name,surname") })
Please note that as documentation says
These are only used if table generation is in effect. Defaults to no additional indexes.
columnlist
, as shown above, accepts column names list as a comma-delimited list.
If you don't use JPA 2.1 you can just use old Hibernate
s @Index
annotation (note this is already deprecated). There's attribute columnNames
where you can pass array of column names no matter above which field it is declared.
@Index(name = "IDX_MYIDX1", columnNames = { "id", "name", "surname"})
Use @Index annotation and use the parameter "columnList" to set which columns should be used to make your index. That list should be made of a comma-separated list of values of the column names.
Important: Don't forget to add the column name property (via Column annotation) to all properties that make this index, otherwise you'll get an error when starting up your container.