Hibernate 4.0.0 CR5
MySQL 5.1.53
In hibernate.cfg.xml I have hbm2ddl.auto set to "create" (for setting up a new system), and I am using MySQL via com.mysql.jdbc.Driver and Hibernate's MySQLDialect.
I have a unidirectional unique many-to-one mapping in hibernate.hbm.xml, like this:
Code:
<class name="Event" table="events">
...
<many-to-one name="application" class="Form" column="application_form_id" unique="true" not-null="true"/>
...
</class>
Hibernate then sets that up with the following (reasonable) SQL:
Code:
create table events (..., application_form_id bigint not null unique, ...)
alter table events add index FKB307E1197DBAB500 (application_form_id), add constraint FKB307E1197DBAB500 foreign key (application_form_id) references forms (form_id)
The issue is that MySQL automatically creates an index for columns marked "unique", and Hibernate also explicitly creates a foreign key index for the mapping. This results in two indexes for the same column, one unique and one not -- the one that Hibernate creates is unnecessary in this case and ends up just taking up space in the database.
I can remove this index manually I suppose, but, is there a way to make Hibernate not create the unnecessary additional index?
Thanks!