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