Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to modify Hibernate's auto-generated running serial number?
    primarykey
    data
    text
    <p>I am using <strong>Hibernate</strong> (JPA) with <strong>Derby database</strong> - my app server is <strong>Jboss 6.0</strong>. 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 <strong>JPA</strong> (since it runs within app container).</p> <p>My Employee class is an Entity bean and has "<strong>Id</strong>" column being primary key with "<strong>@GeneratedValue(strategy = auto)</strong>" annotation so that Hibernate figures out the appropriate running serial no for the primary key (i.e. Id column).</p> <p>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 <strong><em>Entitymanager::persist()</em></strong>, I always get <strong>constrain violation</strong> error like "<em>duplicate key value in a unique or primary key constraint or unique index</em>". This is because hibernate tries to insert the new entry with <strong>Id =1</strong> where as I already have an entry in that table with Id = 1.</p> <p>My question is </p> <p>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 <strong>at all</strong>?</p> <p>b) Is there any other way to achieve the same?</p> <p>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?</p> <p>Thanks in advance for any suggestion, - kuntal </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload