aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes JPilot,, Java ranch exam question ID: 21 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 "JPilot,, Java ranch exam question ID: 21" Watch "JPilot,, Java ranch exam question ID: 21" New topic
Author

JPilot,, Java ranch exam question ID: 21

Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
When a session bean has container-managed demarcation value of 'Supports', which "three" methods run in an unspecified transaction context?

A.
ejbActivate

B.
getRollbackOnly

C.
getUserTransaction

D.
ejbRemove

E.
afterBegin

F.
afterCompletion

Correct answers are A,D,F

I thought F is incorrect since afreCompletion() runs without transaction context and I think E should be correct, since the TX attribute is supports, so if the calling application runs in UTC, this session bean also runs in UTC so implicilty afterBegin() runs in UTC.


Any comments?

Miki


Miki<br /> <br />SCJP 1.4, SCBCD 1.3
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
I thought F is incorrect since afreCompletion() runs without transaction context


EJB specs page 76

A session bean�s newInstance, setSessionContext, ejbCreate, ejbRemove, ejbPassivate,ejbActivate, and afterCompletion methods are called with an unspecified transaction context.

I think E should be correct, since the TX attribute is supports, so if the calling application runs in UTC, this session bean also runs in UTC so implicilty afterBegin() runs in UTC.



EJB specs page 76

A session bean�s afterBegin and beforeCompletion methods are always called with the same transaction context as the business methods executed between the afterBegin and beforeCompletion methods.

Although the above paragraph says that the afterBegin is always called in the the transaction context of the business method but it doesn't makes any sense that these methods will be called if the calling application runs in UTC.

If there is no transaction then afterBegin() logically shouldn't be called. I am not sure what specs say about this.Other experts please comment.

Hope that helps.


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
If there is no transaction then afterBegin() logically shouldn't be called. I am not sure what specs say about this.Other experts please comment.

I am no expert but I will try and help.

When a new transaction begins, the afterBegin() method is then invoked to inform the stateful session bean of this fact. The afterBegin() method is therefore invoked with the transaction context, so database updates may be done in this method.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
When a new transaction begins, the afterBegin() method is then invoked to inform the stateful session bean of this fact. The afterBegin() method is therefore invoked with the transaction context, so database updates may be done in this method.


The point is if the calling application is running in unspecified transaction context then is afterBegin() called?

Logically I think that it shouldn't be called but I am not sure. In specs I am not able to find anywhere that afterBegin() runs woth UTC.
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
Sawan, thanks for clearing that the afterCompletion() is always called in UTC. I remember somewhere on this forum reading that it would be called without TX context.

Roger, regarding your comment:
The afterBegin() method is therefore invoked with the transaction context


I am not sure this is true. The spec says (pg 76, 7.5.6):
A session bean's afterBegin() and beforeCompletion() methods are always called with the same transaction context as the business methods executed between afterBegin() and beforeCompletion() methods


Well, what happens if the TX attribute of the business method is Never :-)

Miki
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
The point is if the calling application is running in unspecified transaction context then is afterBegin() called?


and BTW sawan, the afterBegin() it is always called! spec pg 75, 7.5.3. the third paragraph from the end.

Miki
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Yes Miki it is written that the afterBegin() will be called if SessionSynchronization is implemented. But everwhere in specs whenever the afterBegin() comes in picture it is discussed with a transaction and can;t find anywhere about afterBegin() in UTC.

But if the transaction is not there then there is no need to invoke afterbegin() as this method is there to get the callbacks regarding transactions.

Sometimes what specs say and what I think are different.

Tommorow will do a test and will see if in UTC after begin is called. In between if you guys come up with some conclusion then post it .

sawan
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Remember, the whole point of the javax.ejb.SessionSynchronization
interface is to provide the stateful session bean instances with transaction synchronization notifications.

I haven't got at hand the EJB 2.0 spec, but this is taken from the 2.1 spec:
The afterBegin notification signals a session bean instance that a new transaction has begun.
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
I did a small test on weblogic. The afterBegin is not getting called if the calling application is in UTC. Actually this makes sense.

Yes if the calling method is in transaction then afterBegin() is getting called.

Hope it helps.
[ June 25, 2005: Message edited by: sawan parihar ]
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
sawan , thanks for creating such a test. I will create as well later this week but since I have the exam tomorrow I don't have time now.

However I must say I am surprised that web logic did not throw an exception or so for the test you read. According to the spec the only possible transaction attributes ffor a SB that implements the SessionSynchronization are: required, requiresnew and mandatory. )pg. 352. It is true the spec doesn't mention what should happen if this conditions are not met, so maybe that is why web logic allows it.

Still, this explains the original problem. Thanks both of you for the input.

Miki
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
I will create as well later this week but since I have the exam tomorrow I don't have time now.


BEST OF LUCK
Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Hello, Is ejbActivate() called followed by afterBegin() or you can call ejbActivate() when afterCompletion() finishes?
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
All these methods are callback methods.You do not call them.Container calls them due to various events that occur


With Regards,<br /> Rajan<br />"Java Rocks"
Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
All these methods are callback methods.You do not call them.Container calls them due to various events that occur


Hi, Page 309 of HFEJB states "The Container calls the bean's ejbActivate() method ... The bean runs ejbActivate() before it runs the business method that triggered the activation." So for a passivated session bean that implements SessionSynchronization interface, the order of events will be:

1) ejbActivate runs, followed by afterBegin, beforeCompletion and lastly, afterCompletion.

OR is ejbActivate the last one to run?

2) afterBegin runs, followed by beforeCompletion, afterCompletion and lastly ejbActivate.

Thank you.
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
Originally posted by Shanel Jacob:


Hi, Page 309 of HFEJB states "The Container calls the bean's ejbActivate() method ... The bean runs ejbActivate() before it runs the business method that triggered the activation." So for a passivated session bean that implements SessionSynchronization interface, the order of events will be:

1) ejbActivate runs, followed by afterBegin, beforeCompletion and lastly, afterCompletion.

OR is ejbActivate the last one to run?

2) afterBegin runs, followed by beforeCompletion, afterCompletion and lastly ejbActivate.

Thank you.


Refer to page number 352 and 510 you will be able to get a clear picture.

-ejbActivate()
-Business method() (because of a call to this the bean is activated)
-beforeCompletion()
-afterCompletion()

will be the sequence of calls.
Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
Thanks for the tip Rajan. I've not gotten that far in the book yet but I hope to cover them this weekend.

One point though, in the sequence you've listed, afterBegin() was left out.

-ejbActivate()
-Business method() (because of a call to this the bean is activated)
-beforeCompletion()
-afterCompletion()


From the book, it says that afterBegin() runs BEFORE the business method and transaction commits BEFORE afterCompletion().

So I will update the sequence you've given, do let me know if it makes any sense.

Sequence 1 - ejbActivate()
Sequence 2 - afterBegin()
Sequence 3 - Business method
Sequence 4 - beforeCompletion()
Sequence 5 - Commits transaction
Sequence 6 - afterCompletion()
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
Originally posted by Shanel Jacob:
Thanks for the tip Rajan. I've not gotten that far in the book yet but I hope to cover them this weekend.

One point though, in the sequence you've listed, afterBegin() was left out.



From the book, it says that afterBegin() runs BEFORE the business method and transaction commits BEFORE afterCompletion().

So I will update the sequence you've given, do let me know if it makes any sense.

Sequence 1 - ejbActivate()
Sequence 2 - afterBegin()
Sequence 3 - Business method
Sequence 4 - beforeCompletion()
Sequence 5 - Commits transaction
Sequence 6 - afterCompletion()



I forgot to put afterBegin().
It could be commit / rollback at sequence 5.
[ November 11, 2006: Message edited by: Rajan Murugan ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPilot,, Java ranch exam question ID: 21