wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes HFE vs EJB Spec - session beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "HFE vs EJB Spec - session beans" Watch "HFE vs EJB Spec - session beans" New topic
Author

HFE vs EJB Spec - session beans

cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
Hi,
On p.228 of HFE, we can read that in ejbCreate and ejbRemove methods of stateless session beans, we are not allowed to get a transaction reference, and call methods on it (BMT only).
On, p.90 of EJB2.0 spec, it's clearly mentionned that we can call getUserTransaction on ejbCreate and ejbRemove methods of BMT stateless session beans (although it's not allowed to call setRollBackOnly and getRollbackOnly of CMT beans).
Which one to trust;-)?
Second question:
why is it allowed to access Ressource mananger and Enterprise Beans in ejbCreate, ejbRemove, ejbPassivate and ejbActivate methods of stateful session beans whereas it is not allowed for ejbCreate and ejbRemove methods of stateless session beans?
Thanks for your response,
Regards,
Cyril.


SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287
Ramakrishna Allam
Ranch Hand

Joined: Mar 23, 2004
Posts: 34
HF EJB says that its possible only for BMT .. And u can not call getUserTransaction on CMT stateless ....its the same thing that spec says ..

2. In stateless beans , ejbCreate() is not called when the client calls create() on home. But its called when the container thinks that its necessary to create the bean instances . So , the ejbcreate() doesnt have security context in case of SLSB.
but in SFSB(stateful session bveans) , jbCreate() is called when the client calles create() on home and hence ejbCreate() has security context available in it .
EJB spec says that access to resources and other beans is possible if the method has either transaction context or security context. Though both the SLSB and SFSB ejbCreate methods do not have transaction context , SFSB has security context . So , in SFSB , ejbCreate can access Res mgrs and other beans .
cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
HF EJB says that its possible only for BMT .. And u can not call getUserTransaction on CMT stateless ....its the same thing that spec says ..

Hmmm... I don't change my question: The spec says you may call getUserTransaction on BMT Beans (look at the right cell of the table p.90 for ejbCreate and ejbRemove methods) whereas HFE says it's not possible ( the box "get a transaction reference, and call methods on it BMT beans" is unchecked...p.228)
That's clearly different;-)
Regards,
Cyril.
Ramakrishna Allam
Ranch Hand

Joined: Mar 23, 2004
Posts: 34
yeah....U are right.
Infact ejbCreate() , ejbRemove() of both SFSB , SLSB are not in transaction context. So , setRollbackOnly and getRollbackOnly()(for CMT beans) methods cann not be accessed (in both SFSb and SLSB). this is true for ejbActivate() and ejbPassivate() methods of SFSB .
But in all the cases , if the bean is a BMT one , its possible to call the getUserTransaction() method in all the methods .(I do not undertsand why!!.When there is no transaction context running , (infact) when an unspecified tranction context is running , will it be possible to call getUserTransaction[ofcourse in BMT]). If that is the case , EJB spec should be right for the above Q'n . i.e getUserTransaction can be called from stateless ejbCreate and ejbRemove . Somebody please explain . this is really confusing .
Constantino Cronemberger
Greenhorn

Joined: Mar 03, 2004
Posts: 12
On page 90 of the spec. it says you can call getUserTransaction for BMT, but it does not say you can call methods on this UserTransaction.
Have a look at the business method row. There you can find the line "UserTransaction" methods.
Constantino Cronemberger
Greenhorn

Joined: Mar 03, 2004
Posts: 12
Another interesting thing to notice on page 80 of the spec. is that on ejbCreate you can access "enterprise beans" even though there is no meaningful transaction context. This goes against what is said on page 81:
"Accessing resource managers and enterprise beans is disallowed in the session bean methods for which the Container does not have a meaningful transaction context or client security context."
Ramakrishna Allam
Ranch Hand

Joined: Mar 23, 2004
Posts: 34
Hi Constantino,
I got this doubt earlier and got clarified in this forum only . SO , I will be enlightening u this time , thanks to my great helping nature :-)(just kidding) . EJB spec on page 81 says that , "Accessing resource managers and enterprise beans is disallowed in the session bean methods for which the Container does not have a meaningful transaction context or client security context." . Observe the OR part as well , "client security context" . ejbCreate() , ejbRemove() , ejbActivate() and ejbPassivate() [4 methods] have client security conetxt though they do not have the transaction context.(that is the reason why we can call gerCallerPrincipa and isCallerInRole() in those methods) .So , we can access resource mgrs and other enterprise beans as well in those 4 methods. But only in case of SFSB . In case of SLSB , we have neither transaction context nor security context . So , we can not access resource mgrs and other beans .
If this is the case, i have got another doubt which hasnt been clarified . afterCompletion in CMT stateful method , though doesnt have transaction context , has a security conetext . But surprisingly, it doesnt have access to resource managers and other enterprise beans . If u understand why , please let me know.
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Originally posted by Constantino Cronemberger:
On page 90 of the spec. it says you can call getUserTransaction for BMT, but it does not say you can call methods on this UserTransaction.
Have a look at the business method row. There you can find the line "UserTransaction" methods.

Not sure if this is errata. I checked up EJB1.1 specs,
the same table, same row and column has "UserTransaction methods"
for ejbCreate()/ejbRemove() methods for SLSB. (p:74, 6.8.2, Table 3).
EJB1.1 has errata list on the website and this is not mentioned there.
But the same table mentioned in EJB2.0 and 2.1 specs, do not have this as
Constantino pointed out. So I am also confused , as nothing changed in Session beans from EJB1.1 to EJB2.1
Coming to Kathy's book, this is not mentioned in the Unconfirmed errata list at the OReilly site.
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Originally posted by Ramakrishna Allam:
If this is the case, i have got another doubt which hasnt been clarified . afterCompletion in CMT stateful method , though doesnt have transaction context , has a security conetext . But surprisingly, it doesnt have access to resource managers and other enterprise beans.

- How can I forget this question ...I am trying to get the answer from other forums as well and will post the answer here, if I manage to get a convincing one. Hope Kathy/Bert would come around and post the correct explanation before that.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: HFE vs EJB Spec - session beans
 
Similar Threads
getUserTransaction() in ejbCreate() for stateless session bean
Doubt in access of tx stuff in stateless and stateful bean
question about ejbCreate() and ejbRemove() in Stateless SB or MDB
Unspecified Transaction Context
Obtaining transction reference for stateless session beans