-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ObjectNotFoundException: No row with the given identifier
PostPosted: Thu Dec 24, 2009 7:41 pm 
Newbie

Joined: Mon Dec 21, 2009 8:51 am
Posts: 6
Hi,

I have a problem with my application using Hibernate 3.2.

I have several dialogs loading data, displaying it, and saving them. The dialogs are all the same because I copied the code, only the fields have been changed (entity, address, bank account). For entities and address everything works fine, but with the bank accounts I get an ObjectNotFound exception when try to save the new record to the database and refreshing the view reloading the data. The strange thing though is that the record is properly saved. When I click on a mamual refresh button, which uses the same code, the data is also properly shown. Only when I savie it and immediately call the refresh it doesn't work and I have no idea why.

The session is also commited before I refresh, so it shouldn't be a problem with the session to my understanding. Any idea where I could look for to find out what the problem is?


Top
 Profile  
 
 Post subject: Re: ObjectNotFoundException: No row with the given identifier
PostPosted: Fri Jan 15, 2010 8:05 pm 
Newbie

Joined: Mon Dec 21, 2009 8:51 am
Posts: 6
I finally found out what the problem was. In case somebody has a similar problem, I find it quite usefull if people also post their solutions, so when you find it on google you may know what it was, so here is mine.

My application works like this that the user enters some data via a dialog. Before I save the row I do a select with the primary key and look if a similar record is already existing. If yes, then I just copy over the data and update it, otherwise it is saved.

However when the record didn't exist, then load() is throwing an unrecoverable exception (which is documented). The problem why I didn't find it though is, that the commit() comes much later on a different part, and only then Hibernate gave me the error message, so I was looking in the wrong place of the code. The solution was to use get() instead of load() and catch and ignore the exception for ObjectNotFound.

So maybe somebody will find that info usefull when encountering a similar problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.