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

Moderator: admin

Post Reply
ETS User

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

Post 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?

kezman9
Posts: 26
Joined: Fri Jul 06, 2012 1:08 am
Location: Poland
Contact:

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

Post 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).

sanju.ait@gmail.com
Posts: 38
Joined: Fri Aug 16, 2013 11:37 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Did you read the explanation?
If you like our products and services, please help us by posting your review here.

sanju.ait@gmail.com
Posts: 38
Joined: Fri Aug 16, 2013 11:37 pm
Contact:

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

Post 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.

sanju.ait@gmail.com
Posts: 38
Joined: Fri Aug 16, 2013 11:37 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

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

Post by ramy6_1 »

Hello ,

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

Please confirm.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

Post 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 ?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

Post 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.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

aazizi.tarik
Posts: 31
Joined: Sun Dec 27, 2015 1:47 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

mB() will not throw any exception because it will not even be invoked. The container will throw an EJBException to the caller.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests