-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Optional assigned primary keys with @Id @GeneratedValue?
PostPosted: Tue Mar 06, 2007 4:23 pm 
Newbie

Joined: Wed Dec 08, 2004 6:04 pm
Posts: 4
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.