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 Problem while Retreiving the value from DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem while Retreiving the value from DB" Watch "Problem while Retreiving the value from DB" New topic
Author

Problem while Retreiving the value from DB

Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
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

Joined: Oct 08, 2010
Posts: 132

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

Joined: Apr 15, 2008
Posts: 70
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

Joined: Jul 26, 2011
Posts: 416
    
    4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem while Retreiving the value from DB