Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!