Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while Retreiving the value from DB

 
Parthiban Malayandi
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
 
rohit chavan
Ranch Hand
Posts: 132
Hibernate Java Oracle
  • 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 ?
 
H Paul
Ranch Hand
Posts: 471
4
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic