I use Hibernate (JPA) with Derby base - my Jboss 6.0 application server . I had to pre-populate a table of 50,000 with employee information, and for this I used the stand-alone JDBC program. Now from my application I also need to insert new information about the employee on the fly, in the same table, and at that time I use JPA (since it works in the application container).
My Employee class is an Entity bean and has an Id column that is the primary key with the annotation @GeneratedValue (strategy = auto) , so the Hibernate digits output the corresponding serial number no for the primary key (for example, an identifier column).
Now the problem is that Hibernate always starts this serial number with "1", even if there are already entries in the Employee table. Thus, from the application, when I try to insert a new record using Entitymanager :: persist () , I always get a constrain violation error as "duplicate key value in unique or primary key constraint or unique index". This is because hibernate is trying to insert a new record with Id = 1 , where, since I already have a record in this table with Id = 1.
My question
a) how can I update the Hibernate cache so that my serial number for the "Id" column can be adjusted accordingly? I understand that it will be different from DB to DB - but is this even possible ?
b) Is there any other way to achieve the same?
c) If I write a standalone JPA program to do a volume insert (for example, pre population), and then run the Jboss application, can sleep mode determine the correct "production series" no?
Thanks in advance for any suggestion, - kuntal
source
share