File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

composite key

 
Joe Jose
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Jose
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Joe Jose
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic