Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Auto generated primary key in hibernate?

  Asked By: Elliott    Date: Jul 08    Category: Java    Views: 3371
  

I need sample code about access auto generated primary key in hibernate.
plz help me.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Norman Ray     Answered On: Jul 08

when you generate your hbm file ,your auto  generated primary  key is like this:


<id name="id" type="long">
<column name="ID" />
<generator class="native" />
</id>

then you only need set your value object without setting id and persist it .

 
Answer #2    Answered By: Leon Evans     Answered On: Jul 08

In Hibernate mapping file

using this code  we can automatically generate the primary  keys


<id name="emp number" type="integer">
<column name="emp number"/>
<generator class="increment"/>
</id>

 
Answer #3    Answered By: Garai Chalthoum     Answered On: Jul 08

There are some algorithms that can be used for PK generation, please have a look at:
www.hibernate.org/.../mapping.html

Some of them can be used on specific databases, while others like 'increment' can be used for all databases. There are some performance considerations with this approach.

 
Didn't find what you were looking for? Find more on Auto generated primary key in hibernate? Or get search suggestion and latest updates.




Tagged: