Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating composite primary column

 
Unnati Redkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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), and then save the entity, which will force the creation of a new primary key/compound key set.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic