aspose file tools*
The moose likes Object Relational Mapping and the fly likes Auto increment key  in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Auto increment key  in Hibernate" Watch "Auto increment key  in Hibernate" New topic
Author

Auto increment key in Hibernate

kala praveen
Greenhorn

Joined: Nov 04, 2004
Posts: 21
Hi,

I am facing a peculiar problem with Hibernate. I have an application which uses Hibernate and inserts data into database. While inserting a row which is having an auto increment column as primary key into database Hibernate is giving me duplicate integrity constraint exception. Outside the application I may simultaneously insert data into the same table.

My doubt is : Doesn't Hibernate get latest auto generated key from database while inserting data into a table? How to overcome this problem?


Thank you,
Kala.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

It depends on how you set it in the configuration file. Whether you have native or not. And like in Oracle if you use a sequence table, naming the name of the sequence table in the Java file that is mapped to that table.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
kala praveen
Greenhorn

Joined: Nov 04, 2004
Posts: 21
Thank you Mark. It got resolved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auto increment key in Hibernate
 
Similar Threads
set the values
Reg. Updation in MySQL Database using Hibernate.
Auto Generate Primary Key
Getting primary keys
Hibernate Mapping- composite id (pk+ foreign key)