This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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: 17250
    
    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.
 
Don't get me started about those stupid light bulbs.
 
subject: Auto increment key in Hibernate