• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to do hibernate mapping using natural key(s)

 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems everywhere people are using surrogate keys like the following

<hibernate-mapping>
<class name="Department" table = "dept"
<id name="id" type="long" column="id">
<generator class="native/sequence/..."/>
</id>
...


What if I have to deal with a natural key table, for example

dept(name, address) where "name" is the PK. How do I create that <id> section ?? Anybody can help ??

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use the "assigned" generation strategy.
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
You use the "assigned" generation strategy.


thanks. if I omit this line

<generator class="assigned">

Is it true that, by default, hibernate picks "assigned" ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic