• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Ranch Hand
Posts: 237
MyEclipse IDE Firefox Browser 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,
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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.
 
author and cow tipper
Posts: 5000
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
MyEclipse IDE Firefox Browser 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
Posts: 5000
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
 
Grow a forest with seedballs and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic