aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Life cycle CallBacks for Enterprise beans 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 "Life cycle CallBacks for Enterprise beans" Watch "Life cycle CallBacks for Enterprise beans" New topic
Author

Life cycle CallBacks for Enterprise beans

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9386
    
    2

Guys,

Can this be said of the life cycle callbacks for Enterprise beans?

All the life cycle callbacks for Stateless, Stateful, Entity and Message driven beans run in an unspecified Transaction and security context?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Yes, that's true for session and message-driven beans. The PostConstruct, PreDestroy, PrePassivate and PostActivate methods run in unspecified transaction and security contexts.

However, for Stateful session beans you have two minor differences:
- You can call EJBContext.getCallerPrincipal() and EJBContext.isCallerInRole().
- afterBegin() and beforeCompletion() are invoked with a transaction context. This is not the same for afterCompletion() which is invoked after the transacion has completed.


For entity beans (section 3.5 of the JPA specification):

When invoked from within a Java EE environment, the callback listeners for an entity share the enterprise naming context of the invoking component, and the entity callback methods are invoked in the transaction and security contexts of the calling component at the time at which the callback method is invoked.

[ September 08, 2008: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Darned JPA components complicating things!!!

Great answer!

-Cameron McKenzie
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
I just want to summarize the above reply:
For call back listener method:
Stateless session beans: unspecified transaction context & security context
Stateful session beans: unspecified transaction context & security context
Entity: same trasaction & secuirty contexts.
In addition, for stateful session beans:
afterBegin() and beforeCompletion() - same transaction context but unspecified security context
afterCompletion() - unspecified transaction & secuirty context.
Please correct me if I am wrong.


Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9386
    
    2

Great reply guys. Thanks!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9386
    
    2

But does the afterBegin() and beforeCompletion() belong to the life cycle of a Stateful session bean? In my post I've mentioned only about the lifecycle callbacks if they occur in an unspecified transaction and security context.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Life cycle CallBacks for Enterprise beans