• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Question about accessing another bean's methods

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to understand the rules for when it is permissible for a bean to access the methods of another bean. I thought that this could be done while the bean was in a transaction. If this is the case then why can it be done in ejbCreate() for a session bean?

My understanding is that you can specify a transaction attribute for the ejbCreate() methods of entity beans but not session beans. Does the container automatically assign a transaction attribute of "Required" to certain session bean callbacks? Why is it permissible to access another EJB from ejbCreate(), ejbActivate(), ejbRemove(), and ejbPassivate() but not afterCompletion()?

Robert
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to remember that there are two types of session beans -- stateless and stateful. When a client calls create on a stateless session bean, the bean was created a long time ago and no ejbCreate will be invoked because of it. That's not true for a stateful session bean so it's valid to access other beans since in ejbCreate there will be a valid transaction at that point.

There same is true of afterCompletion or whatever ... there's no transaction at that point (it's done! that's why the function is there) ... so obviously, you can't access the regular stuff.
 
Robert Miller
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is why is there a valid transaction in ejbCreate when one cannot be specified in the deployment descriptor.

Robert


Originally posted by Nathaniel Stoddard:
You need to remember that there are two types of session beans -- stateless and stateful. When a client calls create on a stateless session bean, the bean was created a long time ago and no ejbCreate will be invoked because of it. That's not true for a stateful session bean so it's valid to access other beans since in ejbCreate there will be a valid transaction at that point.

There same is true of afterCompletion or whatever ... there's no transaction at that point (it's done! that's why the function is there) ... so obviously, you can't access the regular stuff.

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Entity Beans, ejbCreateXXX will be called when the client calls createXXX on the Home interface. An entity bean is taken out from the pool by the container and a database record is assigned to the entity bean object. Hence, one or more database read/write is required during ejbCreateXXX.

Also as ejbCreate is a container call back method, it is not a business method and deployment descriptor has nothing to do with this, but as database read/write is involved when the callback happens, hence transaction is a must.
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic