This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

EJB 3.0 Transaction Question

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Quote your sources
 
Ranch Hand
Posts: 65
Hibernate Firefox Browser Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Tony Tung
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 .
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic