| Author |
operation allowed in different methods
|
Imran Vohra
Ranch Hand
Joined: Dec 12, 2005
Posts: 77
|
|
According to EJB Spec for stateless session bean in ejbCreate() and ejbRemove() method, you can call getUserTransaction() method (for BMT) but not UserTransaction methods. From this I understood that you can get transaction reference but you cannot call methods on it. Am I right? I am confused as in HFEJB book, that particular point is not checked in ejbCreate() and ejbRemover() methods in stateless session bean. another question is of entity bean - in ejbLoad() & ejbStore() method, you can get security info about client (getCallerPrincipal() & isCallerInRole() method), so why it is not possible to get this info in ejbActivate() and ejbPassivate() method. Thanks Imran
|
Regards
Imran
|
 |
Devender Thareja
Ranch Hand
Joined: Jul 14, 2005
Posts: 187
|
|
Originally posted by Imran Vohra: According to EJB Spec for stateless session bean in ejbCreate() and ejbRemove() method, you can call getUserTransaction() method (for BMT) but not UserTransaction methods. From this I understood that you can get transaction reference but you cannot call methods on it. Am I right? I am confused as in HFEJB book, that particular point is not checked in ejbCreate() and ejbRemover() methods in stateless session bean.
UserTransaction can provide you different type of information like ref to your home, rollback a transaction etc. But depending on where is bean's life-cycle your bean is, certain action may not make sence. That's why you can call certain methods but not others. e.g. in ejbRemove for session bean you can not set transaction to rollback, but you can do that in entity bean because it makes sence there.
Originally posted by Imran Vohra: another question is of entity bean - in ejbLoad() & ejbStore() method, you can get security info about client (getCallerPrincipal() & isCallerInRole() method), so why it is not possible to get this info in ejbActivate() and ejbPassivate() method. Thanks Imran
ejbActivate() and ejbPassivate() here are called by container. If entity bean is inactive for a while and not in transaction then container may decide to passivate it, there may not be client at that time, hence get security info is not applicable for these methods. [ December 28, 2005: Message edited by: Devender Thareja ]
|
Devender Thareja
SCEA, SCBCD, SCJP
|
 |
Sankar Subbiramaniam
Ranch Hand
Joined: Oct 03, 2000
Posts: 116
|
|
According to EJB Spec for stateless session bean in ejbCreate() and ejbRemove() method, you can call getUserTransaction() method (for BMT) but not UserTransaction methods. From this I understood that you can get transaction reference but you cannot call methods on it. Am I right? I am confused as in HFEJB book, that particular point is not checked in ejbCreate() and ejbRemover() methods in stateless session bean.
You are right. In case of stateless beans with Bean Managed Transaction (BMT), you can get a reference to the javax.transaction.UserTransaction object in ejbCreate() and ejbRemove() methods. But you can call methods (eg: commit(), getStatus() )on this object only in business methods. A generic rule: When in doubt always follow the rule mentioned in EJB specs.
another question is of entity bean - in ejbLoad() & ejbStore() method, you can get security info about client (getCallerPrincipal() & isCallerInRole() method), so why it is not possible to get this info in ejbActivate() and ejbPassivate() method.
Look at the Lifecycle diagram of Entity beans: ejbLoad() and ejbStore() are performed when the bean is in "method ready state". Although the container determines when to call these methods, they are called due to some client action. (The container cannot on its own modify entries ina database. Isn't it ?) The bean instance is associated with a client context in this state and hence calling those methods are valid. ejbActivate() and ejbPassivate() calls are initiated by container. The container determines when to initiate these operations based on resource availabilty and several other parameters. Client actions are not involved. Since there is no client context present when these callback methods are called, you cannot call getCallerPrincipal() & isCallerInRole() methods. [ December 28, 2005: Message edited by: Sankar Subbiramaniam ]
|
 |
B.Sathish
Ranch Hand
Joined: Aug 18, 2005
Posts: 372
|
|
|
This is a mistake in the HFEJB stated in the unconfirmed erratta. You can get UserTransaction reference from ejbCreate() and ejbRemove() of a stateless session bean
|
 |
Imran Vohra
Ranch Hand
Joined: Dec 12, 2005
Posts: 77
|
|
Thanks to all, for your reply. Imran
|
 |
 |
|
|
subject: operation allowed in different methods
|
|
|