How to annotate inherited id with @GeneratedValue and field with @Index within Subclass?
AFAIK, you can't. What you can do is overriding attributes and associations (i.e. change the column or join column) using the AttributeOverride
and AssociationOverride
annotations. But you can't do exactly what you're asking.
For the GeneratedValue
, consider using XML mapping to override the strategy if you don't want to declare it in the mapped superclass.
For the Index
(which is not a standard annotation by the way), did you actually try to declare it at the table level using Hibernate's Table
annotation instead (I'm assuming you're using Hibernate)?
@Table(appliesTo="tableName", indexes = { @Index(name="index1", columnNames=
{"column1", "column2"} ) } )
creates the defined indexes on the
columns of table tableName.
References
- JPA 1.0 Specification
- Section 2.1.9.2 "Mapped Superclasses"
- Section 9.1.10 "AttributeOverride Annotation"
- Section 9.1.11 "AttributeOverrides Annotation"
- Section 9.1.12 "AssociationOverride Annotation"
- Section 9.1.13 "AssociationOverrides Annotation"
- Hibernate Annotations Reference Guide