Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Life cycle CallBacks for Enterprise beans

 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darned JPA components complicating things!!!

Great answer!

-Cameron McKenzie
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great reply guys. Thanks!
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
catch it before it slithers away! Oh wait, it's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic