-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate generates unnecessary index with MySQL.
PostPosted: Tue Jul 02, 2013 11:31 pm 
Beginner
Beginner

Joined: Sun Jan 11, 2009 2:47 pm
Posts: 21
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.