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: 4133

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



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" />

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"/>

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:

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.