-
1. Re: Exception Handling (w/ interceptor)
gavin.king Sep 13, 2006 5:34 PM (in response to texan)Just call setRollbackOnly().
This is a perfectly reasonable pattern, Seam 1.1's built-in exception handling does much the same thing. -
2. Re: Exception Handling (w/ interceptor)
texan Sep 13, 2006 6:53 PM (in response to texan)I tried the following and my transaction is still not rolling back! (Notice I'm purposefully generating a null pointer exception in my save so I can test this.)
Also note that, as described above, the EJBException that I'm throwing is being handled in my interceptor which is not rethrowing it.@Name("viewUser") @Stateful @Conversational public class ViewUserAction implements ViewUser { @In(required = false) @Out(required = false) private User editUser; @PersistenceContext(type = PersistenceContextType.EXTENDED) private EntityManager em; (other attributes and methods removed...) public String save() { try { if (editUser.getId() == 0) { em.persist(editUser); } // throw an exception String user = null; user.toString(); } catch (Exception e) { try { em.getTransaction().setRollbackOnly(); } catch (Exception xe) {} throw new EJBException(e); } return "edituser"; } }
-
3. Re: Exception Handling (w/ interceptor)
gavin.king Sep 14, 2006 4:43 AM (in response to texan)em.getTransaction() is NOT the right way to get access to the JTA transaction (it should be throwing an exception).
instead you need to call EJBContext.setRollbackOnly(). You can get the EJBContext from JNDI or by injecting it using @Resource. -
4. Re: Exception Handling (w/ interceptor)
texan Sep 14, 2006 9:27 AM (in response to texan)Oops - stepped in it again! Thanks for your patience.
-
5. Re: Exception Handling (w/ interceptor)
texan Sep 14, 2006 10:04 AM (in response to texan)I did get this working, but I had to back out the Seam jars from CVS, as I couldn't figure out how to avoid hitting the Seam "ExceptionInterceptor". I'm sure there's a simple way to define my interceptor to occur just before that one, but at the moment I'm content with Seam 1.0.1.
One question - how did the Seam ExceptionInterceptor class bypass my "catch" clause? In the "save()" method that I included above, the catch clause was never reached if I used the 9/10/2006 CVS jars. Instead, the Seam exception interceptor kicked in, even if I changed my catch to "Throwable". That is, I was single stepping through the code, and once I threw the null pointer with "user.toString()", it went straight to your interceptor! -
6. Re: Exception Handling (w/ interceptor)
gavin.king Sep 14, 2006 11:53 AM (in response to texan)I did get this working, but I had to back out the Seam jars from CVS, as I couldn't figure out how to avoid hitting the Seam "ExceptionInterceptor".
@Interceptor(within=ExceptionInterceptor.class)One question - how did the Seam ExceptionInterceptor class bypass my "catch" clause? In the "save()" method that I included above, the catch clause was never reached if I used the 9/10/2006 CVS jars. Instead, the Seam exception interceptor kicked in, even if I changed my catch to "Throwable". That is, I was single stepping through the code, and once I threw the null pointer with "user.toString()", it went straight to your interceptor!
This is really difficult to believe.... -
7. Re: Exception Handling (w/ interceptor)
texan Sep 14, 2006 12:21 PM (in response to texan)Well, I'll see if I can package up an example, but with my luck, it will not work as I described... :-)