• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

composite key

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul.
reply
    Bookmark Topic Watch Topic
  • New Topic