• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Foreign Keys

 
Gundum Hoi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that if I generate my DB schema with Hibernate...it will name all the foreign keys with generated meaningless names such as "FK87627BFE12D20136".

I don't think I like it.

1) is there a way to have my own meaningful names ?
2) if I handcraft my own FK referential integrity into the DB... can I generate the FK from DB to hbm.xml ?

Thank you.
 
Ed Degeyter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gundum,

Are you using the 'column' attribute in the elements that represent a relationship? For instance,

<many-to-one name="pojo_name" column="foreign_key" />

I've let hibernate generate the tables in this example ( http://www.coderanch.com/t/216384/ORM/java/Query-woes-determined-but-struggling ) and the foreign keys were what I labelled them.

Hope this helps...
 
Gundum Hoi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Degeyter,

I don't mean the name of the foreign key column...which you can set with

<many-to-one name="pojo_name" column="foreign_key" />

actaully what I have is

<many-to-many column="foreign_key_col_name" class="pojo_class_name"/>

What I meant is the name of the foreign key. The CONSTRAINT `FK87627BFEB05CCE91` FOREIGN KEY ... part of the create table statement.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic