• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JNDI lookup to get access to the EJB

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I am sorry my question is wrong , we should use SessionContext for lookup operations.
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • 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
  • 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]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic