-->
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.  [ 2 posts ] 
Author Message
 Post subject: Updating object for its composite key columns
PostPosted: Sun Jun 08, 2008 2:16 pm 
Newbie

Joined: Tue Oct 02, 2007 1:47 am
Posts: 6
Hi,

Looking at updating an hibernate composite key object for modified either or all of the composite key fields. I tried :

1. load the object.
2. create new object for new composite key values.
3. set the not null fields for new object from the old t this new object
including the associations, while making the primary id of each associate
object as null - since the id generator: class=increment for all of these
associations.
4. hibernate.update(new object)
5. delete the old object : hibernate.delete(old obect)

This gives me an error message : failed to lasily initialise the association.
If i comment the piece of code for setting null for primary keys of the all the associations for the new object - constarint violation exception is thrown.

What am i missing? will my update for composite key, update the corresponding associations as well for their new updated foreign key?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 08, 2008 3:28 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
So, isn't updating a primary key somewhat against the whole idea of a primary key?

Shouldn't it just be a simple load of the record (object) , evict the object, delete a clone of the object, set the primary keys of the evicted record to zero, which will save the record with new a new primary/compound key.


-Cameron McKenzie

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.