• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

operation allowed in different methods

 
Ranch Hand
Posts: 77
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all, for your reply.

Imran
 
reply
    Bookmark Topic Watch Topic
  • New Topic