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

Moderator: admin

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

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

Post by himaiMinh »

For the explanation of option 5:
The container automatically wraps the exception into a RemoteException for remote client if required.
I believe with EJB 3.0, the exception is wrapped into an EJBException unless the remote method throws RemoteException.

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

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

Post by admin »

That is what the statement means. It says, "...if required" at the end. That means in certain cases the container may wrap it into RemoteException whenever it is necessary.
If you like our products and services, please help us by posting your review here.

Igor Makarov
Posts: 14
Joined: Tue Sep 08, 2015 3:27 am
Contact:

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

Post by Igor Makarov »

Hi. Could you please explain one of the correct option.

It's not clear from the explanation why this option is correct:
"If the bean can recover from the exception, the method should throw an application exception without setting the transaction for rollback only."

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

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

Post by admin »

This is a general programming recommendation given by the specification in Chapter 14. Basically, if the exception received by a bean in course of its execution is such that there is no impact on the bean's consistency then there is no reason to roll back the transaction by the bean itself. It should throw an application exception and let the client decide what it wants to do.
For example, lets say you have a client that is trying to book a flight itinerary and it calls a bean method to book first ticket and then it calls the method again to book second connecting flight. Now, if while booking the second flight the bean internally receives an exception because the flight number is invalid, then there is no need for the bean to roll back the whole transaction right there. It can throw something like InvalidFlightNumberException to the client and let the client decide whether it wants to try with another flight or cancel the ticket for first leg.
On the other hand, if the bean receives some database related exception, it can decide there is some serious issue and there is no way this transaction can complete correctly, and it can then mark the transaction for roll back and throw a system exception to the client.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post by johnlong »

Could you please answer the following question:
If bean throws EJBException (or any other system exception) and catches it before exiting the same method , will the container be aware of requirement to mark transaction as rollback only(or rollback transaction)?

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

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

Post by admin »

No, for rollback to happen, the exception has to be thrown out of the bean method. If a bean code gets a system exception and catches it, that means this bean hasn't thrown any exception to the container. So no automatic rollback.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post by johnlong »

I see, thanks.

mcqueide
Posts: 4
Joined: Sat Oct 15, 2016 12:03 pm
Contact:

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

Post by mcqueide »

If it is a checked exception that is not listed in the throws clause of the method and if the bean cannot recover from this exception, the bean method should throw the javax.ejb.EJBException that wraps the original exception.
I think where is checked exception should be unchecked exception, because all checked exception has to be listed in the throws clause of the method.

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

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

Post by admin »

No, it is correct. The checked exception is not listed in the throws clause that is why the statement is talking it about wrapping it in EJBException. If the checked exception were declared in the throws clause, there wouldn't be any reason to wrap it into an EJBException.
If you like our products and services, please help us by posting your review here.

mcqueide
Posts: 4
Joined: Sat Oct 15, 2016 12:03 pm
Contact:

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

Post by mcqueide »

I think you should change checked exception for application exception, because application exception can be runtime exception(unchecked exception) or checked exception. So if the exception was a runtime exception marked with @ApplicationException, it may not be present in the throws clause and the bean method should throw the javax.ejb.EJBException.

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

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

Post by admin »

But the question is about what should be done when you want to throw a checked exception and it is not listed in the throws clause.
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 30 guests