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

Hibernate problem Edit ID

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Object that has a composite ID (made up of three items) FirstName, lastName and SSN. The requirement is that a user can modify the firstName. Considering that the firstName is part of the Primary Key. It means i have to delete the current Object and create a new Object based on the deleted Object. How do I tackle this in Hibernate

Many thanks in advance
 
Andreas Erber
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abiodun Adisa,

in general this should not be that hard: retrieve the item from the database, copy its values to a new instance, delete the old instance (esp. in the DB) and then save the new one.

But before you go on, you should probably rethink your design. This operation you are trying to accomplish is not straight forward because it is bad style. You should never be in need to change a primary key. This will usually lead to inconsistent data if the database does not keep track - and will cause you a lot of trouble if the database keeps track.

Use a surrogate primary key and put a UNIQUE constraint on your triplet of entries. This is much better and easier to handle.

CU
Froestel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic