• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mock exam question

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone

Folowing is a question from mock exam (difficult question 1/20) given at www.ejbcertificate.com

Q. Which of the following statements are true when a session bean's client receives a java.rmi.RemoteException? [Check all correct answers]

1 The client will never receive a java.rmi.RemoteException.
2 The client calls the session bean from another JVM.
3 The client calls the session bean from within the same JVM.
4 The container throws a java.rmi.RemoteException if the container performs a transaction rollback.
5 The throws clauses of all methods in the remote home and component interface must declare a java.rmi.RemoteException.

The answer given is options 2, 4 and 5. along with the following explanation :

The Container catches a non-application exception; logs it (which can result in alerting the System Administrator); 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 the javax.ejb.EJBException (or subclass thereof) to the client if the client is a local client.

I think option 4 is not correct because the container need not always throw
java.rmi.RemoteException whenever it rolls back a transaction. Am I correct?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's correct. If a CMT bean instance throws an application exception from a method running in a container-initiated transaction (Required, RequiresNew), the container will rollback the transaction and re-throw the application exception as is (not a RemoteException) to the remote client (EJB 2.0 spec, Table 15, p. 376).
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Valentin Crettaz:
That's correct. If a CMT bean instance throws an application exception from a method running in a container-initiated transaction (Required, RequiresNew), the container will rollback the transaction and re-throw the application exception as is (not a RemoteException) to the remote client (EJB 2.0 spec, Table 15, p. 376).



Valentin, Is this correct ???

Acc to my understanding if the bean throws App Exception , the tx is not rolledback automatically (the instance needs to do this by calling setRollbackOnly() ). But it happens when it throws a system exception !!!.
(table 15 on page 376 of the spec).
pls correct me if I am wrong.
thanx
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is important to differentiate between:
- the container rolls back the transaction; and
- the instance rolls back the transaction

When the container initiates a transaction, it is the only one who can roll it back because neither the client nor the instance is aware that a transaction has been started by the container.

Table 15 says that the container's action when an application exception has been thrown is to rollback the transaction in case the instance called setRollbackOnly OR attempt to commit the transaction. In either case, the application exception is rethrown. This is just to point out that option 4 was wrong, i.e. that the container does not necessarly throws a RemoteException when a transaction is rolled back.
 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx valentin,

Just another ques.
1. If Bean in caller's tx -> system exception -> container marks tx for rollback
2. If bean in container's tx -> system exception -> container rollback the tx.

Now, is there any diff between container "marking" the tx for roll back and container "rolling back" the tx. Why does the container only marks for rollback the first one ???
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The convention is that the guy who created a transaction should be the sole responsible for rolling it back. Other actors can only "advise" the transaction initiator to roll back or not a transaction by using setRollbackOnly(). The transaction initiator will then invoke getRollbackOnly() and act accordingly. It would not be a good idea to let someone rollback a transaction that has been started by someone else, or would it?
 
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 Giju George:
Thanx valentin,

Just another ques.
1. If Bean in caller's tx -> system exception -> container marks tx for rollback
2. If bean in container's tx -> system exception -> container rollback the tx.

Now, is there any diff between container "marking" the tx for roll back and container "rolling back" the tx. Why does the container only marks for rollback the first one ???



Excuse me Giju, does point 1 refer to BMT?
 
reply
    Bookmark Topic Watch Topic
  • New Topic