-->
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: Prevent Hibernate from creating Indexes for Foreign Keys
PostPosted: Tue May 24, 2011 10:53 am 
Newbie

Joined: Tue May 24, 2011 10:34 am
Posts: 1
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?


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.