aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EJB 3.0 Transaction Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EJB 3.0 Transaction Question" Watch "EJB 3.0 Transaction Question" New topic
Author

EJB 3.0 Transaction Question

Tony Tung
Greenhorn

Joined: Aug 07, 2009
Posts: 17
A developer is working on a user registration application using EJB 3.0.
A business method registerUser in stateless session bean RegistrationBean performs the user registration.
The registerUser method executes in a transaction context started by the client.
If some invalid user data causes the registration to fail,
the client invokes registerUser again with corrected data using the same transaction.
Which design can meet this requirement?

A. Have registerUser method call EJBContext.setRollbackOnly() method after registration fails

B. Have registerUser method throw javax.ejb.EJBTransactionRequiredException after registration fails

C. Have registerUser method throw EJBException without marking the transaction for rollback, after registration fails

D. Create an application exception with the rollback attribute set to false and have registerUser method throw it after registration fails


I got the Answer is D , but I think it may be wrong because Application Exception must have Rollback = True
to get automatic rollback if it is not rumetimeexception or any uncheck exception .

A option is wrong , reason is below list
The setRollbackOnly and getRollbackOnly methods can only be
invoked in an EJB using CMT with these transaction attributes: REQUIRED,
REQUIRES_NEW, or MANDATORY. Otherwise, the container will throw an
IllegalStateException.

B option javax.ejb.EJBTransactionRequiredException seem not to exist

C option is only one could be right answer .

Will someone could answer this question ? thanks a lot
Tony Tung
Greenhorn

Joined: Aug 07, 2009
Posts: 17
sorry , javax.ejb.EJBTransactionRequiredException exist .

But EJBException is subclass from RuntimeException , if you custom application exception into RuntimeException
, Maybe D option could be right answer .
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

Please Quote your sources

[My Blog] [JavaRanch Journal]
Vignesh Murali Natarajan
Ranch Hand

Joined: Jul 24, 2006
Posts: 65

Tony Tung wrote: I got the Answer is D , but I think it may be wrong because Application Exception must have Rollback = True
to get automatic rollback if it is not rumetimeexception or any uncheck exception .


Hi,
Option D is the right answer in my opinion because the problem statement clearly states that the client should be able to use the same transaction to correct the problem


ThanQ,
Vignesh Murali N
www.vigneshmurali.com
SCJP(95%), SCWCD(92%), SCBCD(97%), SCDJWS(97%), SCBCD5(100%), OCMJEA
Tony Tung
Greenhorn

Joined: Aug 07, 2009
Posts: 17
Vignesh Murali Natarajan wrote:
Tony Tung wrote: I got the Answer is D , but I think it may be wrong because Application Exception must have Rollback = True
to get automatic rollback if it is not rumetimeexception or any uncheck exception .


Hi,
Option D is the right answer in my opinion because the problem statement clearly states that the client should be able to use the same transaction to correct the problem



Dear Natarajan

Refenece Enterprise JavaBean 3.0 , Application Exceoption set Rollback by default (=faulse) mean it would not
automatically to rollback , but give oppertunity to recorrect data in the client . because no action excuting before
exception is throw , so nothing to need rollback .

I think D option is right to this situation .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 Transaction Question