openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heiko Kopp <it-media.k...@daimler.com>
Subject Re: EntityNotFoundException caused by EntityManager.refresh()
Date Fri, 16 Apr 2010 19:26:33 GMT

Hello Mike,

first let me thank you for your help in this issue. It is really appreciated
that for OpenJPA there is a great chance to get assistance in these kind of
situations.


Michael Dick wrote:
> 
> I wish I had a more elegant solution to offer you. Something like this
> will also work : 
>         p = em.find(Person.class, 1);
>         System.out.println(p);
>         
>         try {
>             em.refresh(p);
>         } catch (EntityNotFoundException enfe) {
>             // If a related entity (Address) has been deleted in the
> database an EntityNotFoundException
>             // will be thrown. 
>             // To recover try refreshing again (OpenJPA will not refresh
> the same missing row a second time).
>             em.refresh(p);
>             assertEquals(2, p.getAddresses().size());
>         }
> 
> Whether this is better than calling em.find() is a matter of opinion. 
> 
> Hope this helps, 
> -mike 
> 

This will work perfectly for me. I just need to make sure that in any case I
call refresh and the external modification of the database might have
happened, I make sure that the entity not found exception is caught. It is
good to know, that a subsequent refresh() will not try to refresh the
missing record. 

Interesting for me is, that although the exception is thrown, in case of
refreshing on the Person and assuming that there is not only one
CascadeType.REFRESH-typed OneToMany-relationship is present in person. How
the heck (aeh hell) shall I find out WHERE the entity is no longer found ;-)
It's not important for me right now, but really informative is something
else .... 

For now, thank you very much again.

Greets,

Heiko
-- 
View this message in context: http://n2.nabble.com/EntityNotFoundException-caused-by-EntityManager-refresh-tp4901557p4914750.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message