• 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 session and entity beans

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A stateless session bean can call the EJBContext.getUserTx() in the ejbCreate() and ejbRemove(). But, then why can't it NOT invoke the user tx methods there ???

Also

In a stateful session bean's ejbActivate and ejbPassivate, we can call getCallerPrincipal() and isCallerInRole().. where as we cannot do the same in entity bean's ejbActivate and ejbPassivate...........
WHY ??
[ July 07, 2004: Message edited by: Giju George ]
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Giju George:
A stateless session bean can call the EJBContext.getUserTx() in the ejbCreate() and ejbRemove(). But, then why can't it NOT invoke the user tx methods there ???



It can't call the Container managed transaction because the during these methods, container doesn't have a valid transaction. But u can create your own transactions using EJBContext.getUserTransaction();

Also



In a stateful session bean's ejbActivate and ejbPassivate, we can call getCallerPrincipal() and isCallerInRole().. where as we cannot do the same in entity bean's ejbActivate and ejbPassivate...........
WHY ??



After ejbPassivate the entity beans goes into a pool state, that means it is not attached to a client and similarly when ejbActivate is called bean is in the pooled state and hence no client.
[ July 07, 2004: Message edited by: Giju George ]
 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, then why can we call the methods in stateful session bean's ejbActivate and ejbPassivate ?? There also it's not attached to a client !!!
[ July 07, 2004: Message edited by: Giju George ]
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Giju,

Could you explain me, How will you get the EJBContext in session beans? setSessionContext method of the session bean is called with the parameter, SessionContext not with the EJBContext.

Where as for your second question, in statefull bean's ejbActivate and ejbPassivate methods, you are having the reference to the client, hence you can call getCallerPrincipal() methods.

I hope i am correct...
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The thing to remember about ejbActivate and ejbPassivate is that they have completly different meanings for Session beans versus Entity beans.
HFEJB has a good synopsis on page 308.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Narasimha, SessionContext extends EJBContext ...
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It can't call the Container managed transaction because the during these methods, container doesn't have a valid transaction. But u can create your own transactions using EJBContext.getUserTransaction();



- You can only call EJBContext.getUserTransaction(); if you are using BMT and the Container has nothing to do here.

- To create your own transaction you have to call methods on UserTransaction and the point is you can't do that! Or is it the case that you can call some methods but not others??? In this point I have the same doubt as Giju: if you can't call methods on it then why the heck can you get a ref to UserTransaction in the first place???

As for activate/passivate Giju, for stateful session beans they are used by the container when a client takes too long between calls. The bean is sent to sleep whith passivate but the client still exists. When the bean wakes up (because the client finally made another call) it can also access the client's info. The client is there all along!

For entity beans activate/passivate do something different. When a bean goes out of the pool to "play the role" of a particular entity (Jhon Malcom, #28) ejbActivate is called. At this stage it doesn't know who the client is, it's just focused on becoming Jhon Malcom. When the bean finishes it's performance and goes back to the pool, ejbPassivate is called. The bean doesn't know who the client was anymore and it doesn't care. It just needs to stop playing Jhon Malcom, go back to the pool and be just a bean again. See pages 348-355 of HFEJB.
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A stateless session bean can call the EJBContext.getUserTx() in the ejbCreate() and ejbRemove(). But, then why can't it NOT invoke the user tx methods there ???



As far as I know (from HFEJB), stateless session bean ejbCreate()/ejbRemove() can only do these:
1. get EJBHome object
2. get EJBObject
3. get reference to the JNDI context

It cannot call EJBContext(or more precisely SessionContext.getUserTransaction()) to get the UserTransaction.

Am I right?
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See page 90 of the spec. You can call getUserTransaction but you can't call methods in the UserTransaction you get.

Can anyone explain why you can get the transaction if you can't use it???
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right, slsb ejbCreate can call getUserTransaction() but not to call any method on it.

A bit (actually very) disappointing with HFEJB. As this is not the first time it gives me some technical info not consistent with the spec. This is not the only place it happens, e.g. P406 mentions the dot navigation cannot terminate on CMR field, but this is incorrect. Spec says so long as the CMR field returns a single value it is allowed.

I just wonder how many wrong info given by HFEJB
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They miss some details here and there but look at how large the content for this exam is ... no single book can tell everything ... I think it's up to us to dig into the details like we're trying to do here ... too bad none seems to be answering ...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic