File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enthuware Question doubt

 
Amandeep Singh
Ranch Hand
Posts: 850
  • 0
  • 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.
 
Arun Kumar Gupta
Ranch Hand
Posts: 33
  • 0
  • 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: 850
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it has not been annotated with @ApplicationException.
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Java Spring
  • 0
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic