aspose file tools*
The moose likes Object Relational Mapping and the fly likes relation without ID attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "relation without ID attribute" Watch "relation without ID attribute" New topic
Author

relation without ID attribute

Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
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
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: relation without ID attribute