File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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,
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

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


Perfect World Programming, LLC - iOS Apps
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?

I agree. Here's the link:
subject: relation without ID attribute
It's not a secret anymore!