Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statelsess Beans

 
Mike Pandey
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a simple question in place.
Can we use SessionContext object in ejbCreate() of a stateless bean to get a ref to EJBObject? ?

In HFEJB it says YES...but i want to know how?...as the ejbCreate() is calld at the will of container and I believ EJBObject won't be created until client makes a call.

Pls advice

Thanks
 
Greg Charles
Sheriff
Posts: 3002
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is yes, you can. Why? That's still unclear to me. I've posed the question in several places, including this forum, and I haven't got a satisfactory answer, except that the spec says you can do it, so you can do it.
 
Mike Pandey
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Greg,

thnx for replying back.

Well..Just a step further I guess I have got the ans to this..In the EJB 2.0 spec, on page 90 it says
"Invoking getEJBObject is disallowed if the session object identity is not associated with the bean instance and shud throw IllegalStateException cause the access to this particular SessionContext methd is not allowd"

which means if the container goes on creating a pool before any request comes..then this stmt will hold true.

What say?

As am just a starter, hope we r going the correct way!!
Others please share ur thoughts!!
Thanks a lot!!
 
Greg Charles
Sheriff
Posts: 3002
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Mike,

Well, that's not exactly what it says. Yes, any calls on the session context not allowed in table 3 (also on page 90) should cause an IllegalStateException. Also from that page:

Invoking the getEJBObject and getEJBLocalObject methods is disallowed in the session
bean methods in which there is no session object identity associated with the instance.


However, that is just explaining why getEJBObject is not allowed by table 3 in certain places. Although, it would seem to be true for ejbCreate, table 3 specifically allows getEJBObject in ejbCreate. That doesn't make sense to me, and so far no one has been able to explain it, not even the people who claim it makes sense to them.

The practical consequences aren't very important. For the test, just memorize what the spec says for this case. For real life, don't access getEJBObject from the ejbCreate method for stateless session beans. There's no particular reason you'd have to anyway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic