Hi there,
I have an entity whose primary key getter is tagged @Id @GeneratedValue, which is how I normally want it to behave.
However, I also want to export my tables using a Java task, clear the tables (e.g. for schema changes) and re-import the records under the same primary key they previously held.
Unfortunately, setting my primary key attribute seems to have no effect once I call em.persist() or em.merge().
This is essentially what I'm doing:
Code:
EntityTransaction tx = em.createTransaction();
tx.begin();
while (record = read()) {
MyThing thing = new MyThing();
thing.setId(parseId(record));
em.persist(thing);
}
tx.commit();
Interestingly, when I run my import process from a data set of 810 files, I end up with 514 records in my table, and they all have generated IDs between 1 and 514, whereas the original IDs range, with some gaps, from 1 to 850 or so.
Removing the @GeneratedValue from my primary key getter temporarily allows me to import my records under their original keys, but I would really like to find some way to do so that doesn't require changing and recompiling my entity class. :)
Is there another JPA annotation, or failing that, a proprietary Hibernate annotation I can add that will allow me to accomplish what I'm trying to do?
Thanks!