Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

EJB 3.0 Annotation giving problem with servlets

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi I created an EJB and tried to call it using EJB annotation ( as given in all books ) it worked.Then i created a servlet and tried to call the EJB using @EJB annotation it gave me a Null Pointer Exception however when i called it using JNDI reference it returned me proper result ,Can Anybody explain me reason for this , or i am doing something wrong
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be Java version is creating a problem
 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhay Agarwal wrote:May be Java version is creating a problem


No dear this is surely not the case , i think its not able to inject dependency (EJB 3.0) ,but exactly i cant say....
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your servlet running in the same JVM as the EJB?
 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Potter wrote:Is your servlet running in the same JVM as the EJB?


I created an EAR file with a War file and an EJB module , deployed it in Glassfish.... @ejb gives me an error (Null Pointer ) when i try to call this EJB from my servlet but the same annotation run fine in the way its given in Manning Book , then I tried to call it using JNDI from servlet and whew !!! it worked , I cant understand why @EJb annotation is not working for me in servlet .....
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again taking a guess
- Which version of JSP/Servlets are using to run your sample code ?

Refer to this URL
http://www.javabeat.net/articles/100-new-features-in-servlets-25-1.html

@EJB is supported in Servlets 2.5 and above
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic