openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: EntityNotFoundException caused by EntityManager.refresh()
Date Fri, 16 Apr 2010 20:06:19 GMT

Heiko Kopp wrote:
> 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.
Glad I could help. 


Heiko Kopp wrote:
> 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

The missing rows are stored in the nested exception, but you have to catch
an OpenJPA specific exception to get them, ie.

        try {
        } catch (org.apache.openjpa.persistence.EntityNotFoundException
enfe) {

            for(Throwable t : enfe.getNestedThrowables()) { 

The toString on the exception will look something like this : 

<openjpa-1.3.0-SNAPSHOT-r422266:931580 nonfatal store error>
org.apache.openjpa.persistence.EntityNotFoundException: The following
instances do not exist in the data store: [3
[org.apache.openjpa.util.IntId], 2 [org.apache.openjpa.util.IntId]]

That's not terribly helpful. You know the primary keys for the rows that
failed (3 and 2 in my testcase), but not the tables that they belong to. You
can get the nestedExceptions again to get to the individual rows, but still 

I've opened JIRA 1633 
to make this friendlier. 

I haven't looked into it in depth but we should be able to provide the table
or entity names in the exception. 

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message