Page 1 of 1

About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Tue Oct 09, 2012 3:44 pm
by ETS User
Could you please clarify the following for me: what happens is the method mA() catches and swallows the javax.ejb.EJBTransactionRolledbackException ?

I would assume that in this case, the transaction would be marked for rollback, the bean B would _not_ be destroyed, since it wasn't called, and the bean A would _not_ be destroyed either, since mA() completes succesfully.

Or would the client get an exception anyway?

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Thu Jul 04, 2013 7:36 am
by kezman9
EJBException is a system exception (it extends RuntimeException) which means that containter will mark bean's A transaction for rollback. In this case client will get EJBTransactionRolledbackException as explained in answer (its transaction context which propagates to bean A has already been marked for rollback).

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Thu Aug 29, 2013 1:10 am
by sanju.ait@gmail.com
Why "The bean B instance will be discarded." is not true.

It thrown runtime system exception, still instance is not discarded, why so?

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Thu Aug 29, 2013 8:37 am
by admin
Did you read the explanation?

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Mon Sep 02, 2013 9:54 am
by sanju.ait@gmail.com
Bean A could have catch system exception from bean B and handled properly instead of just propagating it to container.
In that case bean A instance won't get discarded and also state of transaction could also have been different.

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Mon Sep 02, 2013 9:55 am
by sanju.ait@gmail.com
There is noting mentioned about exception handling, thats why this confusion.

If same thing happened in real exam, what shall we assume about such exception handling?

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Tue Sep 03, 2013 4:13 pm
by admin
You might get a question on the exam where it is not clear whether the exception is caught or not. It is really difficult to make a general rule about what to assume because it really depends on the mind of the question setter. In general, you should not assume anything that requires extra coding.

HTH,
Paul.

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Wed Dec 24, 2014 10:31 am
by ramy6_1
Hello ,

In this case I think mA() will receive transactionrequiredexception right ?

Please confirm.

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Mon May 11, 2015 1:23 pm
by himaiMinh
The explanation says this about bean A:
when it calls B's method, it will get a javax.ejb.EJBException, which is a system exception.... the bean A instance will be discarded. There is no impack on bean B instance.
However, in p.370 of JSR 318, session 13.6.2.6 NEVER,
If the client calls with a transaction context, the container throws the javax.ejb.EJBException...
So, bean B cause the EJBException to be thrown. Why bean B is not discarded ?

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Mon May 11, 2015 8:00 pm
by admin
A Bean is discarded if a system exception is thrown out of the bean to the container. If a bean receives an exception due to some other call, it can always catch it. In this case, there is no reason for the bean to be discarded.

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Tue May 12, 2015 10:12 am
by himaiMinh
So, bean B is not discarded because of these reasons:
1. when bean B is not supposed to run in any transaction context, the container throws the exception.
2. the exception is thrown by the container in step 1, not by bean B.

Bean B is not discarded.

Correct me if I am wrong.

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Wed May 13, 2015 9:52 am
by himaiMinh
Regarding to this question, if the client bean has a try/catch block to handle the EJBException thrown from bean A, where the EJBException is caused by the container and the NEVER attribute of bean B,

will the client bean discarded ?

I assume if the client bean can handle any EJBException thrown from other callee bean, the client bean's transaction won't be marked for rollback and won't be discarded.

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Fri May 15, 2015 8:04 am
by admin
Yes, it is the bean that throws a system exception out to the container that is discarded, not the bean that receives such an exception (if it handles the exception). Same with the transaction.

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Sat Jan 16, 2016 6:34 pm
by aazizi.tarik
Could you please say what is the exception thrown from mB()?
Like for example in case of mandatory it throws javax.ejb.TransactionRequiredException?

Re: About Question enthuware.oce-ejbd.v6.2.495 :

Posted: Sat Jan 16, 2016 10:13 pm
by admin
mB() will not throw any exception because it will not even be invoked. The container will throw an EJBException to the caller.