-->
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.  [ 3 posts ] 
Author Message
 Post subject: Updating the PK field of a table.
PostPosted: Fri Feb 13, 2009 6:03 am 
Newbie

Joined: Fri Feb 13, 2009 6:00 am
Posts: 2
Location: India
How do I update the primary key field of my table ??
Everytime I call an update on the record, it creates a new one..

Please help me if I am missing anything !!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 6:51 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
I am afraid this is not possible. Because id field is the identifier of your entity. If there is a change in the identifier field then it semantically means that the entity is different from the previous one.

You wont be able to do an update of the primary key field of an existing row. But what you can do is have the generator for your id field as "assigned" and assign the primary key value you want. If you want to update the key field of an existing row, then create a new entity from the existing entity, may be with a clone and then assign whatever id value you want. Delete the existing entity and save the cloned, changed entity.

Now if I were in your place, what I would do is, have an additional generated key field in ur table and make that one the id field for hibernate. Now whatever is the current id field, make it a unique non-null field.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 7:05 am 
Newbie

Joined: Fri Feb 13, 2009 6:00 am
Posts: 2
Location: India
Thanks Litty. Seems that the delete add method is what I have to do.

I can't add a new id to the table nor can I change the pk field. This is an existing database that we are migrating from EJB to Hibernate.


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

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.