-->
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.  [ 3 posts ] 
Author Message
 Post subject: EntityNotFoundException not thrown by Hibernate JPA
PostPosted: Mon Oct 25, 2010 1:05 am 
Newbie

Joined: Fri Jun 04, 2010 8:57 pm
Posts: 19
I am using the EntityManager#find() method to load a managed entity. The problem is that if the managed entity does not exist in database, EntityNotFoundException is not thrown. Here is the code that I am using.
Code:
        try {
            tran.begin();
            State managedState = em.find(State.class,state.getId());
            tran.commit();
            return managedState;
        }
        catch (Throwable t) {....


If in the database, the given state.getId() does not exists, then I expect that hibernate should throw EntityNotFoundException. But that is not happening.

regards,
Nirvan.


Top
 Profile  
 
 Post subject: Re: EntityNotFoundException not thrown by Hibernate JPA
PostPosted: Mon Oct 25, 2010 11:12 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
What do you get instead? Is it null?


Top
 Profile  
 
 Post subject: Re: EntityNotFoundException not thrown by Hibernate JPA
PostPosted: Mon Oct 25, 2010 11:47 am 
Newbie

Joined: Fri Jun 04, 2010 8:57 pm
Posts: 19
Yes I am getting a null. I think I was misguided by the term EntityNotFoundException. It seems it is thrown in some other situation. Anyway I changed my code accordingly. Thanks.

regards,
Nirvan.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.