Foreign keys have random number appended when using Hibernate's TABLE_PER_CLASS inheritance -
Foreign keys have random number appended when using Hibernate's TABLE_PER_CLASS inheritance -
i have next in domain model:
@inheritance(strategy = inheritancetype.table_per_class) @entity abstract class item { @manytoone @foreignkey(name="fk_item_org") @joincolumn(name="org_id") private organization org } @table(name = "itema") public class itema extends item {} @table(name = "itemb") public class itema extends item {}
hibernate's hbm2ddl creates 2 tables mapping: itema
, itemb
. both have org_id
column , foreign key organization
table. however, each foreign key has random number appended (ie fk_item_org98343). how can specify foreign key each table uses? example, want have fk_itema_org
, fk_itemb_org
.
update
please see follow-on question: is foreignkey annotation used hbm2ddl generate schema?
unfortunately, have remove annotation field in main class , move method in each children providing fk name.
something that:
@inheritance(strategy = inheritancetype.table_per_class) @entity public abstract class item { private organization org; public organization getorg() { homecoming org; } } @entity @table(name = "itema") public class itema extends item { @manytoone @joincolumn(name="org_id") @foreignkey(name="fk_item_org_1") public organization getorg(){ homecoming super.getorg(); } } public class itemb extends item{ @manytoone @joincolumn(name="org_id") @foreignkey(name="fk_item_org_2") public organization getorg(){ homecoming super.getorg(); } }
hibernate foreign-keys hbm2ddl
Comments
Post a Comment