users@glassfish.java.net

Catching Database contraint violations within EJBs

From: <glassfish_at_javadesktop.org>
Date: Fri, 03 Apr 2009 03:52:33 PDT

Good day all,

I have been having an issue for a long time now.
When I try to insert an entity with the entityManger.persiste(), and there is an underlying constraint violation in the database table. I get an exception that I am always not able to catch. I mean for example

try{
       entityManager.persist(o);
}catch (Exception ex){
       ex.printStackTrace();
}

I don't know why control doesn't enter my catch block. Instead, a TransactionRolledBackException or EJBException is thrown and client application often don't deal with this. I found out that the Exceptions thrown are RuntimeException, but RuntimeException is a subclass of Exception, so I assume it should have enter the catch block.

Question
1. What could be wrong with this style of coding?
2. It is advisable to catch a Throwable within my EJBs?

What else could be done.
[Message sent by forum member 'okmich' (okmich)]

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