Meaningless Drivel is fun!
The moose likes Object Relational Mapping and the fly likes composite key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "composite key" Watch "composite key" New topic

composite key

Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125

I have a table with composite ids. I need to update these composite id in certain stage of the project. Is there any way to update this composite ids ? Please help me.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well here is the thing. an ID should never change. If it does, then it is not a good candidate for an ID. An ID has to be unique and unchanging, if it isn't you run into lots of problems, including it not working at all.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Yes, you are right Mark.
Can you suggest any way to solve this without affecting other tables used in the project ? Please help me.

Thanks for your reply.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

The best way it to add a surrogate key to the table currently identified by a composite key.

If you can't change the DDL, you need to define a composite key as per the documentation . Of course as Mark has already pointed out, you can't update this value, only delete and insert. So, presuming you don't have any FK constraints that will prevent you doing this you can simulate an update. If you do, you'll need to change your ER model (not a Hibernate restriction, this is just how relational databases work).

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Thanks Paul.
I agree. Here's the link:
subject: composite key
It's not a secret anymore!