users@glassfish.java.net

Frustrating and Confusing Exceptions

From: <glassfish_at_javadesktop.org>
Date: Tue, 27 Jan 2009 03:24:44 PST

Hi,

We have a method that runs within a new transaction that stores an entity to the database. We're using this method from a normal stateless session bean. Since the data we're storing is coming from an external source we accept that sometimes we might try to store an entity that's already in the database table. We'd like to be able to catch this exception so that we can continue processing other entities. Unfortunately the only way we've been able to do this is to catch a very generic exception, for example, ejbexception and with this we also get a lot of error messages in our log. All I want to be able to do is to find out which exception we should be catching and turn this into an applicationexception so that hopefully no ugly error log messages will appear. I've tried making several persistenceexceptions application exceptions and attempted to catch them but it doesn't seem to work.

We're using hibernate as the persistence provider in our ejb application. I'm not sure if this has anything to do with hibernate or ejb/jpa in general.

Could anyone please give me some advice?
[Message sent by forum member 'woel' (woel)]

http://forums.java.net/jive/thread.jspa?messageID=328361