It's not a secret anymore!
The moose likes Object Relational Mapping and the fly likes Hibernate - Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate - Exception" Watch "Hibernate - Exception" New topic

Hibernate - Exception

Maya sekar
Ranch Hand

Joined: Sep 22, 2011
Posts: 70
Hi Everyone,

I am currently working on a code in hibernate. you know you have the id field in hibernate mapping files,

I understand that the id is mandatory in hibernate and is used to describe the primary key of the table. But my table does not have a primary key since the values of the column can repeat themselves without restriction. But since it is mandatory to define a primary key in hibernate it conflicts with my db and throws an exception when i try to insert duplicate values, like the NonUniqueObjectException Exception.

So is it really "mandatory" to define id in hibernate? Or is it possible to do without it? Or is there another way to resolve this issue....

(am i even making any sense?)

Do help!
Thank you
Have a nice day
sree hareesh

Joined: Nov 16, 2011
Posts: 11
it is must to be identified each object (row of table) uniquely in each object gets its uniqueness using either primary key or composite primary key.if you dont specify primary key or composite key in a table , then you can form composite key using all columns of a table.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 128

Multiple copies of same record in a table is known as redundancy, & this should always be avoided as much as possible. You can have the id field auto-generated instead of keeping it assigned. This should solve your problem.
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3902

Anurag Verma wrote:Multiple copies of same record in a table is known as redundancy, & this should always be avoided as much as possible...

It should be avoided completely!

[How to ask questions] [Twitter]
I agree. Here's the link:
subject: Hibernate - Exception
It's not a secret anymore!