• 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

Using JNDI lookup to get access to the EJB

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , i am new to EJB , using @EJB works fine , but when i tried with JNDI lookup, its not working . The deployment is successful in weblogic10.




Do we need to use @EJB in the servlet when we are not doing Injection ?? Please reply .
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anybody on this please.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry my question is wrong , we should use SessionContext for lookup operations.
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravi,

You have three options:

1. Declare the dependency using @EJB at the class level (most EJB 3 references should cover this).
2. Use XML DD (web.xml) to declare the dependency (WebLogic 10 references should cover this).
3. Use global JNDI names (WebLogic 10 references should cover this).

Why are you using look-ups in this case in the first place?

Regards,
Reza
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. Declare the dependency using @EJB at the class level (most EJB 3 references should cover this).


For stateless session beans , i would do as above .

Use XML DD (web.xml) to declare the dependency




This is where i am getting confused , cant i use sessioncontext.lookup (passing EJB mappedname inside it) without mentioning anything in web.xml ejb-reference ??

Can you please clarify this please

Thanks in advance
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what you mean. The EJB session context is not accessible in the web layer. You cannot use global JNDI names in the EJB context look-up method.

Also, what is it that you are trying to accomplish? Is this an "exam" question? I think the SCBD forum is more appropriate for that sort of thing.

Hope it helps,
Reza
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reza tthanks one more clarification , You mean to say this is not possible??




// Assuming there is a Bean implementation statefull session bean.
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An EJB session context cannot be injected into a Servlet.

Hope it helps,
Reza
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya , Reza , that was nice . Becuase i was getting confused with this :





[url]http://72.14.235.132/search?q=cache:_yNZH_DO8xoJ:www.javapassion.com/j2ee/JavaEE5.pdf+%40resource+sessioncontext+ctx&cd=40&hl=en&ct=clnk&gl=in
[/url]
 
You've gotta fight it! Don't give in! Read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic