Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:40:11+00:00 2026-06-09T06:40:11+00:00

I am new to hibernate and I am facing a strange problem. I am

  • 0

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.

<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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:40:14+00:00Added an answer on June 9, 2026 at 6:40 am

    Try using the native key generator:

    <id column="ID" name="id">
      <generator class="native"/>
    </id>
    

    If your database’s table is already setup to auto-increment the primary key ID’s, then it’ll conflict with hibernate’s auto-increment generator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to hibernate and have stumbled on this problem, which I can't
I'm new to Hibernate and I'm struggling with problem: I have 3 tables and
I am new to Hibernate. I have finished this tutorial and I tried to
Please help me with this hibernate problem, I'm new to hibernate and still trying
very stupid question since I've been using hibernate for some time now but I
I'm new to Hibernate. I'm using Hibernate 4.0 and specifically JPA annotations. I have
Here I am facing an issue in hibernate criteria usage, I have created criteria
I am using Hibernate and I am facing with a really annoying problem, when
I'm new to Hibernate. This is my problem. I can do this: package =
I am pretty new to hibernate and I am stuck at this exception. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.