• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Some doubts about exception handling

 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Eusebio Floriano
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic