users@glassfish.java.net

Re: problem catching the exception in the bean interceptor

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Tue, 15 Sep 2009 14:44:13 -0700

It can happen if the transaction commit happens outside your ejb execution code
(in postInvoke). The exception that you can catch in this block are the
exception from the business method itself.

Try to add em.flush() before exiting your method (but be careful not to flush
too often in the same transaction as it'll affect the performance of your app.

Regards,
-marina

glassfish_at_javadesktop.org wrote:
> I am facing this problem hope to find some solution. Here is the scenario,
>
> I have an ejb interceptor which basically looks like this
>
> EJBInterceptor
> {
>
> @AroundInvoke
> public Object handleExceptions(InvocationContext context) throws Exception
> {
> Exception exception = null;
> Object result = null;
>
> try
> {
> result = context.proceed();
> }
> catch (Exception e)
> {
> exception = e;
> }
> finally
> {
> // some custom functions to do logging....
> }
> }
>
> I have two types of entities A and B. B has reference to A through JPA annotation and also in the database. There is no cascade delete option defined in the database on B though. The relation is a Uni-directional from B -> A in JPA.
>
> Now i call a stateless sesson bean to delete entity A. The problem is i am getting database exceptions in the server log saying that B refers A. However, i am unable to catch in the interceptor. Any thoughts?? I can do work around by deleting B but i still want to know the reason why the interceptor could not catch the exception...
>
> thanks in advance,
> [Message sent by forum member 'eligetiv' (eligati_999_at_yahoo.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=363676
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>