Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ejbCreate for SLSB

 
Li Xin
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to HF EJB page 228, stateless session bean method ejbCreate() and ejbRemove() cannot access a resource manager, so does it mean I cannot create a database connection in ejbCreate and close it in ejbRemove? Can someone explain this?
Thanks.
 
Krishna Thotakura
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right. You cannot access resource managers in the ejbCreate() and ejbRemove() methods. If i understand correctly, it is because these methods do not run in any transaction. And methods that do not run in a transaction cannot access resource managers or other enterprise beans.
Anyone, please correct me if i am wrong.
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it is the case that a method is running in a transaction to access a resource manager. With stateful session beans, resource managers can be accessed in ejbCreate and ejbRemove, although these methods do not run in a transaction.
 
Dilli raj
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For stateless Session bean the resource managers can be accessed only from the Business method. It can neither be accessed from ejbCreate() nor from ejbRemove() method.
[ February 12, 2004: Message edited by: Dilli raj ]
 
Li Xin
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what is the reason for this?
 
Jack Zhou
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According a table 2 in teh ejb2.0 spec on page 80, you do hav access to
to Resource Manager in ebjCreate, ebjRemvoe, ebjPassivate, ebjAcitvate methods
 
Jack Zhou
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, I din't realize that issue is about stateless session. the table 2 is about stateful session baean.
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
keith wrote:
I don't think it is the case that a method is running in a transaction to access a resource manager. With stateful session beans, resource managers can be accessed in ejbCreate and ejbRemove, although these methods do not run in a transaction.

You're right. Running or not in client's transaction context doesn't imply that we may or not access the ressource manager.
For stateful session beans for example, ejbCreate() runs in a "unspecified Transaction Context", although we may access a database inside.
So why do we found such explanations in HFE, p.512, about afterCompletion() method.
You're no longer in a transaction! You can access ONLY your special JNDI context. It's not safe to access resource managers or other beans.

To put it in a nutshell, why do we have sometimes to take care if we are in transaction to access databases (afterBegin() or beforeCompletion() ) and somtimes not (for example ejbCreate() or ejbRemove()).
It's not very clear to me.
Thanks for your help,
Regards,
Cyril.
[ February 14, 2004: Message edited by: cyril vidal ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic