*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Q Relating to Session Sync Stateful SB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Q Relating to Session Sync Stateful SB" Watch "Q Relating to Session Sync Stateful SB" New topic
Author

Q Relating to Session Sync Stateful SB

AmitKumar Jain
Ranch Hand

Joined: Jun 13, 2005
Posts: 95
I have a doubt in question hosted on ejbcertificate.com
Here is the question:
Given that a stateful session bean implements the SessionSychronisation interface, select the correct order in which a container calls a transactional business method that throws a system exception.
1 beforeBegin(), business method, afterCompletion().
2 beforeBegin(), afterBegin(), business method, afterCompletion().
3 afterBegin(), business method, beforeCompletion(), afterCompletion().
4 afterBegin(), business method, afterCompletion().

The answer given is 4. And Explanation given is:
If a business method raises a system exception whilst in the context of transaction, afterCompletion() is called on the session bean instance with a boolean value of false to notify the instance that a rollback has occurred.

Now my concern is... Once a System Exception is raised.. the Container will kill the session bean instance.. then how come afterCompleion be called??


SCJP 1.4 : 91%
SCWCD 1.4 : 95%
SCBCD 1.3 : 95%
SCJP 6 Upgrade : 95%
Next SCBCD 1.5
Man is not finished when he is defeated. He is finished when he quits.
cheenu Dev
Ranch Hand

Joined: Nov 13, 2005
Posts: 276
note this in spec page no:79

Notes:
1. The Container must call the afterBegin, beforeCompletion, and afterCompletion methods if the session bean class implements, directly or indirectly, the SessionSynchronization interface. The Container does not call these methods if the session bean class does not implement the SessionSynchronization interface.

so the afterCompletion method is called before bean is toasted i suppose.


cheenujunk@gmail.com
AmitKumar Jain
Ranch Hand

Joined: Jun 13, 2005
Posts: 95
Well... even in case of beforeCompletion, container calls it once a transaction commit is requested.

It might be possible in case of system exception, that container calls afterCompletion first and then kills the bean... However it is not mentioned anywhere in the spec.

As far as reading spec is concerned, it is not so scary as you mentioned in your mail. Infact, it gives a cool feeling when you find whatever you read from here and there, is all mentioned in the specification. You can reduce the content if you strictly follow only those sections which are mapped in cheat sheet.
AmitKumar Jain
Ranch Hand

Joined: Jun 13, 2005
Posts: 95
Well... even in case of beforeCompletion, container calls it once a transaction commit is requested.

It might be possible in case of system exception, that container calls afterCompletion first and then kills the bean... However it is not mentioned anywhere in the spec.

As far as reading spec is concerned, it is not so scary as you mentioned in your mail. Infact, it gives a cool feeling when you find whatever you read from here and there, is all mentioned in the specification. You can reduce the content if you strictly follow only those sections which are mapped in cheat sheet.
Ugender Rekulampally
Ranch Hand

Joined: Nov 14, 2005
Posts: 130
Amit,
I think afterCompletion() may work like a 'finally' block in try/catch style. This may help cleaning up resource connections or marking some objects to null either transaction goes through or doesn't.
and it makes sense also if my assumption is correct


Thanks,
Ugender
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q Relating to Session Sync Stateful SB