-
1. Re: Catching TransactionRolledbackException
kabirkhan Jul 2, 2004 1:10 PM (in response to pgb)Could you check that the unique constraint is not being validated before the insert/update?
-
2. Re: Catching TransactionRolledbackException
pgb Jul 2, 2004 1:45 PM (in response to pgb)I could check that, however it will mean duplicating the unique constraints both on the DB and on the business layer (Java), and I wanted to take advantage of the DB checking of the contraints, and catching the exception.
Is that possible?
Thank you! -
3. Re: Catching TransactionRolledbackException
aloubyansky Jul 3, 2004 3:13 AM (in response to pgb)You could updateCountry in RequiresNew and catch the exception.
-
4. Re: Catching TransactionRolledbackException
pgb Jul 5, 2004 10:54 AM (in response to pgb)It is still not working with the RequiresNew...
Here's the relevant code (for another bean called Area instead of country):
updateArea method on a session bean:/** * * @param value * * @ejb.interface-method * view-type = "both" * @ejb.transaction * type = "RequiresNew" * */ public void updateArea(AreaValue value) { try { System.out.println("updateArea"); AreaLocal area = AreaUtil.getLocalHome().findByPrimaryKey(value.getPrimaryKey()); area.setAreaValue(value); } catch (FinderException e) { // TODO Auto-generated catch block System.out.println("finder exception"); e.printStackTrace(); } catch (NamingException e) { // TODO Auto-generated catch block System.out.println("naming exception"); e.printStackTrace(); } catch (Exception e) { System.out.println("exception!"); e.printStackTrace(); System.out.println("end exception"); } }
setAreaValue on AreaBean:/** * * @param value * * @ejb.interface-method * @ejb.transaction * type = "Required" */ public abstract void setAreaValue(AreaValue value);
Whenever a unique constraint on the DB fails, I get a TransactionRolledBackException on the JBoss console and I'm not able to catch it...
Thanks again! -
5. Re: Catching TransactionRolledbackException
aloubyansky Jul 6, 2004 2:51 AM (in response to pgb)Show the code that calls updateArea method. updateArea will fail with rollback exception, not that you will be able to catch it inside updateArea.
-
6. Re: Catching TransactionRolledbackException
pgb Jul 7, 2004 9:58 AM (in response to pgb)This is the calling code:
protected final ActionForward executeSave(ActionMapping mapping, BaseCRUDForm form, HttpServletRequest request, HttpServletResponse response) throws CRUDBusinessAccessException { if (form.isNew()) { return executeCreate(mapping, form, request, response); } else { ActionForward retValue = null; try { retValue = executeUpdate(mapping, form, request, response); } catch (TransactionRolledbackException e) { System.out.println("could not update"); } catch (RemoteException e) { System.out.println("remote exception"); e.printStackTrace(); System.out.println("fin"); } return retValue; } }
and in a subclass (the code above is a template method)protected ActionForward executeUpdate(ActionMapping mapping, BaseCRUDForm form, HttpServletRequest request, HttpServletResponse response) throws RemoteException { AreaValue value = new AreaValue(); convertFormToValueObject((AreaForm) form, value); GeneralManager gBean = (GeneralManager) getBean(); gBean.updateArea(value); return navigateBack().getActionForward(true); }
I'm getting this error logged to the console:10:48:07,532 ERROR [LogInterceptor] TransactionRolledbackException in method: pu blic abstract void com.mark2k.siac.services.interfaces.GeneralManager.updateArea (com.mark2k.siac.domain.comitentes.model.AreaValue) throws java.rmi.RemoteExcept ion, causedBy: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImp l [FormatId=257, GlobalId=barney//37, BranchQual=] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Store failed; CausedByException is : ORA-00001: unique constraint (MAT.MA_UK) violated
I'm using remote interfaces for the session beans, and local interfaces for the entity beans.
Thanks again! -
7. Re: Catching TransactionRolledbackException
aloubyansky Jul 9, 2004 5:55 AM (in response to pgb)Try to catch just Exception, not TransactionRolledbackException. It might come wrapped into some JBoss exception.