Forums Register Login

Question about accessing another bean's methods

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.

 
+Pie Number of slices to send: Send
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.
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 703 times.
Similar Threads
Doubt about transaction context in statefull session Bean
Why CMT SFSB ejbCreate can access other bean ?
questions?
Unspecified, but meaningful transaction?
stateful CMT, calls from ejbCreate
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:10:26.