aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Some doubts about exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Some doubts about exception handling" Watch "Some doubts about exception handling" New topic
Author

Some doubts about exception handling

Eusebio Floriano
Ranch Hand

Joined: Mar 07, 2004
Posts: 235
Here they go:

1)
At HFEJB pg. 558 there is the following questions and its respective answer.
Q: Client calls a method on a Remote CMT Bean, and the method is marked Mandatory. The caller does not have a transaction context in place wheb the call comes in.
A: The client gets a TransactionRequiredException (a local client would get TransactionRequiredLocalException).

I disagree because TransactionRequiredException is a system exception. So the client would receve a RemoteException or EJBException. am i right ?

2)
In pratice, when will the client receve a TransactionRolledBackException ?

3)
Wich Exception is throwed when the bean is not ready for be passivated and the method ejbPassivate() finishes ?

Thx,


SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Dan T
Ranch Hand

Joined: Jun 15, 2004
Posts: 66
3. Not too sure what exception they will get, but on page 72 of spec, it says "A container may destroy a session bean if the instance does not meet the requirements for serialization after ejbPassivate" (for session beans)
Severin Stoeckli
Ranch Hand

Joined: Jul 21, 2004
Posts: 62
(1) I disagree because TransactionRequiredException is a system exception


-TransactionRequiredException is a system exception
-Anyway, the client would get this exception, there's nothing wrong with a system exception

see also Javadoc: This exception indicates that a request carried a null transaction context, but the target object requires an active transaction.

severin
Severin Stoeckli
Ranch Hand

Joined: Jul 21, 2004
Posts: 62
(2) In pratice, when will the client receve a TransactionRolledBackException ?


Surely you mean javax.transaction.TransactionRolledbackException (not extended byjavax.jms.TransactionRolledBackException):

You will get this exception in a remote client if the business method marks the method as "rollback only", for example.JavaDoc says:

This exception indicates that the transaction associated with processing of the request has been rolled back, or it has been marked to roll back. Thus the requested operation either could not be performed or was not performed because further computation on behalf of the transaction would be fruitless.

Severin
Dan T
Ranch Hand

Joined: Jun 15, 2004
Posts: 66
quote:
(1) I disagree because TransactionRequiredException is a system exception


-TransactionRequiredException is a system exception
-Anyway, the client would get this exception, there's nothing wrong with a system exception

see also Javadoc: This exception indicates that a request carried a null transaction context, but the target object requires an active transaction.

severin


I believe what Vinicius Boson is trying to say is that in HFEJB, it mentions that if a System Exception is encountered, the Container will send it as a RemoteException or EJBException if the client is local.

Actually if you refer to Spec 18.2.2

"The container catches a non-application exception; logs it; and unless the bean is a Message-Driven-Bean, throws the java.rmi.RemoteException (or subclass thereof) to the client if the client is a remote client, or throws javax.ejb.EJBException (or sublcass thereof) to the client if the client is a local cleint."
[ August 03, 2004: Message edited by: Ryan Wong ]
Dan T
Ranch Hand

Joined: Jun 15, 2004
Posts: 66
quote:
(2) In pratice, when will the client receve a TransactionRolledBackException ?


Surely you mean javax.transaction.TransactionRolledbackException (not extended byjavax.jms.TransactionRolledBackException):

You will get this exception in a remote client if the business method marks the method as "rollback only", for example.JavaDoc says:

This exception indicates that the transaction associated with processing of the request has been rolled back, or it has been marked to roll back. Thus the requested operation either could not be performed or was not performed because further computation on behalf of the transaction would be fruitless.

Severin


Adding to Severin's reply, a client will get this Exception if the Bean encountered a system exception if the method is run in the callers transaction.
Eusebio Floriano
Ranch Hand

Joined: Mar 07, 2004
Posts: 235
Originally posted by Ryan Wong:


I believe what Vinicius Boson is trying to say is that in HFEJB, it mentions that if a System Exception is encountered, the Container will send it as a RemoteException or EJBException if the client is local.


Exactly, Ryan.
I confused system exception with runtime exception. I was thinking that is TransactionRequiredException was a runtime exception (and i reliazed that it isn�t) the client couldn�t receve it.
I didn�t pay attention in "throws the java.rmi.RemoteException (or subclass thereof) "

Thx for the help, dudes
Eusebio Floriano
Ranch Hand

Joined: Mar 07, 2004
Posts: 235
Originally posted by Ryan Wong:


Adding to Severin's reply, a client will get this Exception if the Bean encountered a system exception if the method is run in the callers transaction.



I thought that i read in HFEJB that if a client receve a RemoteException (or EJBException for local clients) the client wouldn�t know if the transaction was rolled back.
But i reliazed that it�s the opposite, right ? When the client gets a non system exception that he can�t know if the transaction was rolled back because the container passes to the client the same exception throwed.
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
Originally posted by Vinicius Boson:


But i reliazed that it�s the opposite, right ? When the client gets a non system exception that he can�t know if the transaction was rolled back because the container passes to the client the same exception throwed.


As far as I know the container doesn't rollback a transaction if a checked exception was thrown. It will do that only in the case of a runtime exception on the server side, together with logging the exception, killing the bean and throwing a RemoteException (or subclass) to remote clients, and EJBException to local clients.


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Eusebio Floriano
Ranch Hand

Joined: Mar 07, 2004
Posts: 235
Originally posted by Marco Tedone:


As far as I know the container doesn't rollback a transaction if a checked exception was thrown. It will do that only in the case of a runtime exception on the server side, together with logging the exception, killing the bean and throwing a RemoteException (or subclass) to remote clients, and EJBException to local clients.


Exactly Marco,

But if the client receve a RemoteException (a system exception) he knows for sure that if there was an transaction, it was rolled back.
My point was that if a client recebe a checked exception, he won�t know if the transaction was rolled back because it�s up to bean provider rolls it back, right ?
Dan T
Ranch Hand

Joined: Jun 15, 2004
Posts: 66
I thought that i read in HFEJB that if a client receve a RemoteException (or EJBException for local clients) the client wouldn�t know if the transaction was rolled back.
But i reliazed that it�s the opposite, right ? When the client gets a non system exception that he can�t know if the transaction was rolled back because the container passes to the client the same exception throwed.


For System exceptions:
As a Bean provider, you really dont need to care whether the client knows if it tx rolled back or not. The bottom line is that it WILL be rolled back by the container. If encountered a System Exception, Bean providers are required to throw back the exception to the container, and let the Container handle it. From the spec 18.2.2, it says the bean provider can rely on the container to do these:

1. Transaction in which the bean method participated will be rolled back
2. No other method will be invoked on an instance that threw a non-application exception.
Severin Stoeckli
Ranch Hand

Joined: Jul 21, 2004
Posts: 62
Vivicius wrote:
But if the client receve a RemoteException (a system exception) he knows for sure that if there was an transaction, it was rolled back. My point was that if a client recebe a checked exception, he won�t know if the transaction was rolled back because it�s up to bean provider rolls it back, right ?


right. The client can only figure it out if he participate in the same transaction.

Severin
 
jQuery in Action, 2nd edition
 
subject: Some doubts about exception handling