• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Enthuware Question doubt

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given that MyApplicationException is an application exception, consider the following session bean method -

public void myMethod(int x){
if(x==0) throw new MyApplicationException();
}

If there are no attributes specified in the annotation for MyApplicationException, and if the transaction attribute of the bean is REQUIRED, which of the following statements are correct?


1) The bean instance will be discarded.

2) The transaction will be set for rollback and the bean instance will be discarded.

3) The transaction will be set for rollback but the bean instance will not be discarded.

4) The transaction will not be set for rollback and the bean instance will not discarded.


Explanation-
From the signature of myMethod(), it is evident that MyApplicationException is a runtime exception (because it is not declared in the throws clause). Since, it is given that MyApplicationException is an application exception, @ApplicationException annotation must have been used on the exception class. Further, it is given that no attribute is specified on this annotation, which means that rollback=false.

Thus, when this exception is thrown, the transaction under which the bean method was invoked, will not be set for rollback. The bean instance will not be discarded either.

If MyApplicationException were a simple runtime exception without @ApplicationException, it would have become a system exception, in which case the transaction would have been set for rollback and the instance would have been discarded.


I know the correct answer is 4. But i am confused with the explanation given it says- MyApplicationException is a runtime exception (because it is not declared in the throws clause). Does that means it will now treat this MyApplicationExcepton as RuntimeException(extends SystemException) also it has no @ApplicationException defined. According to this explanation as it is Runtime Exception, the correct anser would have been 2.

Please Advice.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Amandeep Singh wrote:
I know the correct answer is 4. But i am confused with the explanation given it says- MyApplicationException is a runtime exception (because it is not declared in the throws clause). Does that means it will now treat this MyApplicationExcepton as RuntimeException(extends SystemException) also it has no @ApplicationException defined. According to this explanation as it is Runtime Exception, the correct anser would have been 2.

Please Advice.



It say MyApplicationException is runtime exception but it is also given it is an application exception (so it is not system exception).

so the only way it can be if it is annotated with @ApplicationException

and in it no rollback is specified so by default rollback is false is assumed,so tx is not rollback

 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it has not been annotated with @ApplicationException.
 
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Amandeep Singh wrote:it has not been annotated with @ApplicationException.



It says: "If there are no attributes specified in the annotation for MyApplicationException...", so it has been annotated:)
 
Thank you my well lotioned goddess! Here, have my favorite 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
    Bookmark Topic Watch Topic
  • New Topic