• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does a table need primary key to participate in hibernate session?

 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if a table doesnt have primary key then ,is it not possible to retrieve that table data in hibernate?

thanks,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is sort of possible but ill advised. This gets asked a lot in these forums so have a search for a more complete answer, but basically an entity in a relational database that does not have a unique identifier is not able to participate in relationships so is (by definition) not relational data. And you can't expect any tool whose job is to map between relational and OO data to work properly if you are mapping to soemthing that isn't relatioal.

There are workarounds (again, have a search of the forums) but none are perfect.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a client that insisted that primary keys really were not the necessary for oracle tables. Their tables had either no primary key, or a composite primary key referencing four or five tables.

Anyways, it was a complete nightmare. Really, in a relational database, a primary key is an extremely important concept. Hibernate really is fundamentally designed around primary keys and proper foreign keys. As Paul said, you can probably shoe-horn Hibernate into a non primary-key scenario, but I've never seen it done in a production environment, and it's certainly not a best practice.

Is there a situation you're in where you're being forced into tables without primary keys?

-Cameron McKenzie
 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am just learning.



thank you both.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to learn is to ask questions. And we love answering questions! So, just keep asking.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic