Hi im triying to handle a constraint violation but i dont know how.. In my EJB i have this:
try { UserTransaction userTransaction = ejbContext.getUserTransaction(); userTransaction.begin(); em.remove(anyObject); userTransaction.commit(); } catch(Exception ex){ //WHAT DO I HAVE TO DO HERE, FOR HANDLE THE CONSTRAINT VIOLATION??? } The exception class is: javax.transaction.RollbackException Im getting this: openjpa-2.2.0-r422266:1244990 fatal store error> org.apache.openjpa.persistence.EntityExistsException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred. Caused by: <openjpa-2.2.0-r422266:1244990 fatal store error> org.apache.openjpa.persistence.EntityExistsException: Cannot delete or update a parent row: a foreign key constraint... Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Cannot delete or update a parent row: a foreign key constraint fails......... [code=1451, state=23000] I know this exception is because im triying to delete a child before delete his parent, what i want is to check if my object has a reference in other table (i dont want to use a SELECT for each table) that's why i want to handle a constraint violation (can be only the: Cannot delete or update a parent row: a foreign key constraint fails.) how can i do this? If i iterate over the ex.getCause() i only get one. Throwable cause = ex.getCause(); while(cause!=null) cause = cause.getCause(); Im using JTA and OpenJPA 2.2.0 Thanks. ------------------------------------------------------------------- SCJA. José Luis Cetina -------------------------------------------------------------------