File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate: is it necessary to have primary key in table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: is it necessary to have primary key in table" Watch "Hibernate: is it necessary to have primary key in table" New topic
Author

Hibernate: is it necessary to have primary key in table

amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
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 .
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Discussed many times before. A couple of similar posts:

Mapping a table without a primary key

No primary key in database


[My Blog] [JavaRanch Journal]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: is it necessary to have primary key in table