• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

tiers interviening

 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I;m little confused about accessing ejb beans from web tier. It's known that unlike stateless beans, stateful beans shouldn't be accessed from web tier through DI (because of thread safety).
So, Stateful beans should be obtain through JNDI lookup.
I found this examle in book :


and


The thing what bothers me is - should I have an exposed reference on UserRegistration in servlet (where the 'userReg' variable come from???
Considering that in book, this is two portion of code, does whole code should look like :

???
nd if it does, did the @EJB annotation at the begin of the class, actually inject UserRegistration (what would be another purpose of it)?

Thanks
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it maybe look like previous question which is on list today, but it want.
I'm only interest, because the code above has omit, does class-level annotation should inject reference to some stateful bean's interface in servlet (which I should provide). Is that a point of class-level annotation? (Because that is what bother me. The sample code just left out that piece of code)
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slobodan,

@EJB at the class level declares a dependency, it does not do an injection. I believe the relevant sections describe this in detail.

The variable in question is a local variable, not an instance variable. Instance variables are shared and cannot be used to store stateful beans. In real-life situations, stateful bean references are looked up from JNDI and stored in the HTTP session (unless you are using Seam, which does scope management at the web tier declaratively).

Hope it helps,
Reza

 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha, so UserRegistration in my example is local variable, which I simply expose in my servlet. SO does it mean that this my understanding is correct :


Is that-that :-) ?
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slobodan,

You are correct.

Cheers,
Reza
 
It's just a flesh wound! Or a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!