Meaningless Drivel is fun!
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

Auto increment key in Hibernate

kala praveen

Joined: Nov 04, 2004
Posts: 21

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,
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

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.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
kala praveen

Joined: Nov 04, 2004
Posts: 21
Thank you Mark. It got resolved.
I agree. Here's the link:
subject: Auto increment key in Hibernate
It's not a secret anymore!