• 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

relation without ID attribute

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I am updating a table which has no primary key. The table contains only non key attributes. If i want to insert record, Can i do using hibernate? Because in my understanding of hibernate, without an ID attribute, table can't be inserted. How to achieve this?

Help me,
Abu.A
 
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
exactly. Hibernate must have an id field so that it can match the object instance to one and only one record in the database.

If the table does not have a PK field, does it have a unique index or combination of fields that will uniquely identify the single row in the database. If so you can create a composite-id with the composite including all those fields.

If, however, there is no unique combination of fields then you data table can allow duplicates, then Hibernate can't help you there, I recommend using a surrogate primary key, if you are allowed to add one. If not, sorry you are out of luck. We have that with one or two of our tables and we can't change it at the moment, too risky close to a deadline, so we are SOL

Mark
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark,

You are suggesting me my point of keeping an ID attribute in Hibernate is must. If i don't have ID attribute for my relation, I can use Combination of attributes which selects me unique records. That's fine. But four or five of my tables come under 3rd category of having surrogate keys. If i use these surrogate keys, in future, will it disrupt my schema design?

Abu.A
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic