• 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Problem while Retreiving the value from DB

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm learning Hibernate Framework

I did an simple example of One to One Mapping and when I try to select a row I'm getting an exception

Please find the programs I'm using






The Exception I'm getting is


How ever I'm not getting that exception if I un comment the following the tester program


//SchemaExport export = new SchemaExport(config);
//export.create(true,true);

Can somebody let me know what is the problem ?

Thanks in advance
 
Ranch Hand
Posts: 133
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The exception is self explainatory.


Exception in thread "main" org.hibernate.NonUniqueResultException:query did not return a unique result: 2



So, it means you need to check your query to return single record.
 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rohit,

Thanks for your reply, I tried to retrieve a record using a primary key (id), which is supposed to return a unique record,still I'm getting the same exception .

Basically if I have more than one record in DB and when I retrieve a record I'm getting that exception.

Since it's a one to one mapping is Am I making a mistake ?
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. I noticed:
begin transaction
save
read
commit

Should it not be?

begin transaction
save
commit
read

2. I would delete data from the 2 tables and use a debugger and run it again.
While debugging, check the data for those 2 tables.
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic