Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

@EJB annotation for Stateful beans  RSS feed

 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I want to ask about the usefulness of @EJB annotations in case of Stateful Session Beans (SFSB). Of course it's very useful when injecting a Stateless one, but let's see the case for a Stateful: If I have a servlet, MyServlet and a SFSB whose interface is MyCart (with an implemenntation MyCartBean). Inside MyServlet code I'd have something like this:

@EJB
private MyCart myCart;

For the first user of my app this SFSB instance would be ok, but NOT for the next one and on. The SFSB would be injected in the servlet, and as there's only one servlet of each class for the whole app, my SFSB would be shared between all users. So I would have to take care by myself that I look up my session for MyCart, if it's not there I make a look up via JNDI and store it in my session in order not to do it again for the same session. In conclusion, for 1000 users, dependency inyection is used 1 time, and look up via JNDI 999 times. Well, in fact I don't care this, what I really complain about is the fact that a still hace to code a JNDI look up. So, what's the use of dependency injection for SFSB? Isn't there a better and simpler way to do this.

At first I thought that the annotation was enough and the servlet would use a different SFSB for each session (quite optimistic), but it didn't work. People in Geronimo forums told I had to take care of it by myself and I couldn't believe it.

Any coments or answers?

Thank you. Bye!
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The people at Geronimo forum were right. You have to manage it yourself, injecting stateful session beans in servlets is not a good idea, use JNDI lookup for that. See a few old discussions like this one...
 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, people at Geronimo forums helped me very much too. I wanted to be sure it was so not only for Geronimo. In fact I've read Enterprise Java Beans 3.0 (http://www.amazon.com/Enterprise-JavaBeans-3-0-Bill-Burke/dp/059600978X/ref=sr_1_1?ie=UTF8&s=books&qid=1256807040&sr=8-1) and it didn't mentioned it.

Thank you very much! I didn't know about this post you opinted, it was very helpful. Sorry I asked something already answered.

 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's NoNeedToSaySorry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!