openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <>
Subject Re: Handling nesting exceptions (EntityExistsException)
Date Mon, 24 Nov 2008 19:42:09 GMT

The user application needs to scan through the raised exception and its
nested exception(s) recursively to reach at a target exception (e.g.

One of the causes of EntityExistsException is rooted in some sort of 
"Duplicate Key Exception" raised by JDBC driver. Now SQL error code of a
specific SQLException is supposed to be uniform across different databases
but, in reality, it hardly is. So OpenJPA uses a resource file [1] to map
SQL error codes to specific kind of exceptions recognized by the object
management kernel e.g. EntityExistsException or
Populating this resource file with appropriate SQL error code for the target
database will help to narrow down the cause to EntityExistsException and if
you flush() before commit, you are likely to catch EntityExistsException


ruslan wrote:
> Guys, could you please suggest me how you handle attempt to add duplicate
> into table in your application?
> What's the best way of finding exception which I can handle when thrown
> exception consist of bunch of other nested exceptions? Here is example:
>   As you can see topmost is
> 'RollbackException', but I'm interested in first 'EntityExistsException'
> which is real cause. Currently I catch RollbackException, then create List
> of all nested exceptions and looking for ones which I know about such as
> EntityExistsException. But this approach doesn't seem good to me.
> Thanks!

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

View raw message