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

  • SEARCH
  • Home
  • 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 3694066
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:27:08+00:00 2026-05-19T04:27:08+00:00

I am using Hibernate (JPA) with Derby database – my app server is Jboss

  • 0

I am using Hibernate (JPA) with Derby database – my app server is Jboss 6.0.
I have to pre-populate a table with 50000 employee info and for that I have used a standalone JDBC program.
Now from my application I also need to insert new employee info on fly, in the same table and at that time I use JPA (since it runs within app container).

My Employee class is an Entity bean and has “Id” column being primary key with “@GeneratedValue(strategy = auto)” annotation so that Hibernate figures out the appropriate running serial no for the primary key (i.e. Id column).

Now the problem is Hibernate always starts this running serial from “1” even if the Employee table already has entries. Thus from application when I try to insert a new record using Entitymanager::persist(), I always get constrain violation error like “duplicate key value in a unique or primary key constraint or unique index“.
This is because hibernate tries to insert the new entry with Id =1 where as I already have an entry in that table with Id = 1.

My question is

a) how can I update Hibernate’e cache so that my running serial number for “Id” column can be accordingly adjusted?
I understand it will vary from DB to DB – but is it possible at all?

b) Is there any other way to achieve the same?

c) If I write a standalone JPA program to do the bulk insert (i.e. pre population) and then start my Jboss application, will hibernate be able to determine the right “running serial” no?

Thanks in advance for any suggestion,
– kuntal

  • 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-05-19T04:27:08+00:00Added an answer on May 19, 2026 at 4:27 am

    a) how can I update Hibernate’e cache
    so that my running serial number for
    "Id" column can be accordingly
    adjusted? I understand it will vary
    from DB to DB – but is it possible at
    all?

    b) Is there any other way to achieve
    the same?

    • @TableGenerator

    You can generate primary-key using @TableGenerator which generates the next id according to the value in a table maintained having two fields tableName & its respective id & it updates it accordingly after insertion.

    It is responsible for maintaining the correct sequence, you can modify initial value etc.

    @TableGenerator(name = "TABLE_GEN", table = "ID_GEN", pkColumnName = "GEN_NAME", valueColumnName = "GEN_VAL", pkColumnValue = "PERSON_ID", initialValue = 1, allocationSize = 1)
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN")
    private int id;
    

    c) If I write a standalone JPA program
    to do the bulk insert (i.e. pre
    population) and then start my Jboss
    application, will hibernate be able to
    determine the right "running serial"
    no?

    So at the end, create two generators for – 1) application & 2) standalone program, consuming common table for id generation, so there will be no duplicate key value in a unique or primary key constraint or unique index.

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

Sidebar

Related Questions

I'm using Hibernate for ORM of my Java app to an Oracle database (not
I'm trying to setup Spring using Hibernate and JPA, but when trying to persist
I'm using JPA (Hibernate's implementation) to annotate entity classes to persist to a relational
When I make relationsships with JPA using hibernate, some terrible long and ackward column
I'm using Hibernate's implementation of JPA and am seeing poor performance as multiple SQL
I am using Hibernate in a Java application to access my Database and it
I am currently using Hibernate Tools 3.1; I customized naming convention and DAO templates.
So I'm using hibernate and working with an application that manages time. What is
I'm using hibernate validator framework with Spring. A class implementing the Spring Validator validates
We are using Hibernate 3.1 with Spring MVC 2.0. Our problem occurs when data

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.