aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Enthuware Question doubt 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 "Enthuware Question doubt" Watch "Enthuware Question doubt" New topic
Author

Enthuware Question doubt

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
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

Joined: Jul 16, 2008
Posts: 33
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

Joined: Jul 17, 2008
Posts: 844
it has not been annotated with @ApplicationException.
Krzysztof Koziol
Ranch Hand

Joined: Nov 19, 2006
Posts: 133

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


SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCEA/OCMJEA 5.0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Enthuware Question doubt