I have a generic super class with a @ManyToOne tagged property:
Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "vehicle")
@DiscriminatorColumn(...)
abstract class Superclass<T extends Vehicle> {
T entity;
@ManyToOne(cascade = ...)
@JoinColumn(nullable = true)
public T getEntity() {
return entity;
}
...
}
And I have many subclasses that define T:
Code:
@Entity
class Subclass extends Superclass<Truck> {
...
}
Hibernate creates for every subclass the same index for the column "entity_id". Since all instances are stored in the same table, this is unnecessary to have the same index defined many times. It still runs fine with MySQL 5, but it has problems when running against the Derby DB:
Caused by: java.sql.SQLIntegrityConstraintViolationException: INSERT on table 'VEHICLE' caused a violation of foreign key constraint 'FKE125C5CFBE074B58' for key (3).
FKE125C5CFBE074B58 is the name of one of the many indexes created by Hibernate.
How do I fix this to make Hibernate create exactly one index?
How can I prevent Hibernate from automatically creating indexes for foreign keys?