• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Hibernate - Exception

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is must to be identified each object (row of table) uniquely in hibernate.so 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.
 
Ranch Hand
Posts: 171
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Goodbye moon men. Hello tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic