And what about if my object has references in 100 tables? do i have to do 100 SELECT'S??
Is no a more "flexible" way to do it?? 2012/7/19 Pawel Veselov <pawel.vese...@gmail.com>: > Hi. > > On Thu, Jul 19, 2012 at 2:56 PM, José Luis Cetina <maxtorz...@gmail.com>wrote: > >> 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 >> >> [skipped] > >> >> >> 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? >> > > You should do the select. The database will effectively do a select anyway, > to do the constraint check, you are not introducing much overhead. > > There are certain databases, and certain drivers, that will not tolerate > any data exception inside a transaction, and will mark the whole > transaction as "roll back only" should any data exception occur. > > [skipped] > > >> Im using JTA and OpenJPA 2.2.0 >> >> Thanks. >> >> -- ------------------------------------------------------------------- SCJA. José Luis Cetina -------------------------------------------------------------------