NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

how to resolve "javax.naming.NamingException: Lookup failed for” error.

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
bardelman



Joined: 01 Apr 2011
Posts: 9

PostPosted: Tue Apr 12, 2011 8:33 pm    Post subject: how to resolve "javax.naming.NamingException: Lookup failed for” error. Reply with quote

hi !
i m reading the "The NetBeans E-commerce Tutorial" and just trying to do the same in my own project.

An error occurs when trying to access Data with EJBs : After Adding entity beans and session beans(implementing local interfaces) i had to write this code in my servlet :

@EJB
private ProductsFacade productsFacade;

@Override
public void init() throws ServletException {

// store products list in servlet context
getServletContext().setAttribute("products", productsFacade.findAll());
}

but i got this error when servlet is invoked :
javax.naming.NameNotFoundException: session.ProductsFacade#session.ProductsFacade not found

and when trying to look for a solution i found someone who say :

"A common mistake that leads to this error comes from “injections” in your JEE code. In other words, we simply do not indicate the right class to inject due to simply forgetting that in JEE, injections are done through the “local” and “remote” interfaces!!""

it s ok, but i still dont know what i have to add in my code to avoid this problem ?!!

any help please ..
thnx Embarassed
Back to top
Tony
Posted via mailing list.





PostPosted: Wed Apr 13, 2011 9:38 am    Post subject: Re: how to resolve "javax.naming.NamingException: Lookup failed for” error. Reply with quote

Does your ProductsFacade class implement either a remote or local interface? If so, the @EBJ annotation should be changed to reflect the interface, not the implementation class.

Alternatively, delete the @EJB reference and the 'private ProductsFacade ....' line, then use NB's automatic system ..
'Insert code >> Call Enterprise Bean' rather than writing the code in manually. NB should pull in the correct class and/or add in lookup code to enable access to the EJB.

Remember also that the call will fail if the EJB isn't valid .. make sure it has a no-args constructor.

Tony

-----Original Message-----
From: bardelman [mailto:address-removed]
Sent: 12 April 2011 21:34
To: address-removed
Subject: [nbj2ee] how to resolve "javax.naming.NamingException: Lookup failed for” error.

hi !
i m reading the "The NetBeans E-commerce Tutorial" and just trying to do the same in my own project.

An error occurs when trying to access Data with EJBs : After Adding entity beans and session beans i had to write this code in my servlet :

@EJB
private ProductsFacade productsFacade;

@Override
public void init() throws ServletException {

// store products list in servlet context
getServletContext().setAttribute("products", productsFacade.findAll());
}

but i got this error when servlet is invoked :
javax.naming.NameNotFoundException: session.ProductsFacade#session.ProductsFacade not found

and when trying to look for a solution i found someone who say :

"A common mistake that leads to this error comes from “injections” in your JEE code. In other words, we simply do not indicate the right class to inject due to simply forgetting that in JEE, injections are done through the “local” and “remote” interfaces!!""

it s ok, but i still dont know what i have to add in my code to avoid this problem ?!!

any help please ..
thnx
Back to top
bardelman



Joined: 01 Apr 2011
Posts: 9

PostPosted: Wed Apr 13, 2011 9:47 am    Post subject: Re: how to resolve "javax.naming.NamingException: Lookup failed for” error. Reply with quote

Thnx Tony !! it works now Very Happy Very Happy
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo