-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Getting "Unique Key constraint violation" due to "increment"
PostPosted: Wed Aug 08, 2012 12:22 am 
Newbie

Joined: Tue Aug 07, 2012 11:50 pm
Posts: 1
Hi,

I am new to hibernate and I am facing a strange problem.
I am using Hibernate 2.0 and been stuck to this issue since last 2 days.

I have a form which has 2 tables viz. Debit and Credit. Each will hold multiple entries. Each entry will be stored as a separate record in the table. The data from both the tables will be stored in the same table.
I have made an "ID" field as primary key of the table and have configured it as auto increment.
Code:
<id column="ID" name="id">
    <generator class="increment"/>
</id>

When I submit the for the first time, I store the entries in the table which works fine. Auto increment works very well at that time.
In the update action, due to some business logic, I delete all the entries related to each table from the database table and enter the fresh records again. here the problem starts.

I will explain the exact scenario with an example:
I have 2 entries debit and credit each with IDs 1 & 2 and 3 & 4 respectively. Now in the update action, I delete the debit records first (i.e. IDs 1 & 2) and commit the changes. After committing I try to insert fresh set of records for debit. Ideally it should pick the max ID from the table and generate the next IDs (i.e. 5 & 6) for the new records but it gives "Unique Key constraint violation" error.

Can anybody guide on this issue? Has anyone faced similar problem before?
Any pointers would be really appreciated.

Regards,
Ashish


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.