• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPilot,, Java ranch exam question ID: 21

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I will create as well later this week but since I have the exam tomorrow I don't have time now.



BEST OF LUCK
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Is ejbActivate() called followed by afterBegin() or you can call ejbActivate() when afterCompletion() finishes?
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All these methods are callback methods.You do not call them.Container calls them due to various events that occur
 
Shanel Jacob
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic