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 Hibernate and Primary Key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate and Primary Key" Watch "Hibernate and Primary Key" New topic

Hibernate and Primary Key

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I am trying to use the Hibernate Plugin to generate the hbm files for the Application .

But this complains that my Table doesn't have a Primary key .

so i have a question here

Will the Hibernate will not work if the Tables don't have a Primary Key concept ?

Thanks in advance.

Save India From Corruption - Anna Hazare.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

No. But then a relational data model that doesn't define primary keys is arguably broken.

As has been discussed at length in this forum (have a search through the older posts) an entity in a relational database without a primary key cannot be relational so will not work with an Object-Relational Mapping tool. There are partial workarounds (again, a brief search will get you these) but the easiest fix is to correct your data model. Is there a reason you defined an entity without a primary key?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

You need a primary key.

-Cameron McKenzie
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks a lot Paul and Cameron
I agree. Here's the link:
subject: Hibernate and Primary Key
It's not a secret anymore!