• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate: is it necessary to have primary key in table

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to hibernate .I want to know is it necessary to have primary key in table.I real life there are many tables which not has primary key .
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Discussed many times before. A couple of similar posts:

Mapping a table without a primary key

No primary key in database
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate is a Object-Relational Mapping tool. Any data in a database that does not have a primary key is not relational data, since it can't reliably participate in any relationships without a guarenteed identifier. Entity Relational models that contain entities without a defined primary key are, in my opinion, most probably broken.

I say most probably, since there are the odd occasions where you may need to store non-relational data in a database for some other reason. For example, if the database is your only shared, transactional resource it could be use as a simple persistance resource, rather than a truely relational store. However, these situations are very much the exception, not the rule, and Hibernate includes ways round most situations. Where it doesn't, if you are using it with a pattern like DAO its easy enough to delegate to whatever mechanism you use to manage non-relational data.
 
reply
    Bookmark Topic Watch Topic
  • New Topic