I'm using Hibernate 3.2.5.GA, but also tried 3.3.1.GA (with Oracle database and JDBC ver. 11.1.0.6.0) and I'm having problem when naming foreign keys.
First sample code (I've omitted irrelevant parts):
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@SequenceGenerator(name = "SEQ", sequenceName = "SEQ_OBIEKTY")
public abstract class AbstractObject implements Serializable {
@ManyToOne
@JoinColumn(name = "CREATE_BY")
@ForeignKey(name="FK_CB_")
@Index(name = "_CB_I")
protected User createBy;
// ... other fields
}
@Entity
public class User implements Serializable {
// ... user fields
}
@Entity
public class Object1 extends AbstractObject {
// ... specialized Object1 fields
}
When I generate ddl from this model it looks like this (only the foreign key part and index):
Code:
alter table Object1
add constraint FK_CB_72cf927c
foreign key (CREATE_BY)
references User;
create index Object1_CB_I on Object1 (CREATE_BY);
My problem is, when I'm trying to name foreign key in abstract class, the generated foreign key name is: prefix given in @ForeignKey's name annotation plus some random hex number. But analogical index naming results in index name according to: table_name + suffix given in @Index's name annotation. Can anyone explain this to me? Is it a bug, or am I missing something?
Regards,
Maciej