aspose file tools*
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
Author

composite key

Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Hi,

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.

Thanks,
Joe.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
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.

Joe.
Paul Sturrock
Bartender

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: http://aspose.com/file-tools
 
subject: composite key