users@glassfish.java.net

Re: EJB3 NameNotFoundException with simple local sample

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 20 Sep 2007 19:34:34 +0530

I think you should take a look at a web->ejb->jpa example first. Take a
look at a simple example [1] that illustrates the main points.

-- Sahoo

[1]
http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html
angelogeminiani wrote:
> Hi Sahoo,
> I tried add ejb-jar.xml file to my EJB Module.
> But still doesn't work.
> I put ejb-jar.xml file into WEB-INF, is it right?
>
> I need to look up the SimpleBean from the SimplePOJO because my SimplePOJO
> contains an entity manager:
>
> @PersistenceContext (unitName="Test_Sample1-ejbPU")
> private EntityManager em;
>
> Is there another way to create SimpleBean?
> If I do:
> SimpleBean bean = new SimpleBean();
> The EntityManager (em) has not been injected and is null.
>
> Angelo.
>
>
> Sahoo wrote:
>
>> When the SimplePOJO is packaged in the same jar along with SimpleBean, I
>> don't know why you want to look up the SimpleBean from the SimplePOJO.
>> But any way, yes, you need a ejb-jar.xml like this to do a EJB look up
>> from a POJO. Here is an example: (This works as long as SimplePOJO is
>> called in the context of SimpleBean, for the ejb-loca-ref is defined in
>> the env context of SimpleBean only.
>>
>> <ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee">
>> <enterprise-beans>
>> <session>
>> <ejbname>SimpleBean</ejbname>
>> <ejb-local-ref>
>> <ejb-ref-name>ejb/SimpleBean</ejb-ref-name>
>> <ejb-ref-type>Session</ejb-ref-type>
>> <local>packagename.SimpleLocal</local>
>> <ejb-link>SimpleBean</ejb-link>
>> </ejb-local-ref>
>> </session>
>> </enterprise-beans>
>> <ejb-jar>
>>
>> Thanks,
>> Sahoo
>>
>> angelogeminiani wrote:
>>
>>> Hi,
>>> I'm newbie in EJB3 and I've been struggling for 2 days trying to do a
>>> simple
>>> JNDI lookup.
>>> I have a stateless session bean (EJB 3.0) in an EJB Module project, and a
>>> Web Project.
>>> The two projects are packaged in a Enterprise Application project.
>>>
>>> In my EJB Module I have a POJO that need lookup to ebj object
>>> (SimpleBean).
>>> SimpleBean and SimplePOJO are in same EJB Module.
>>>
>>> The EJB:
>>>
>>> @Local
>>> public interface SimpleLocal{
>>> ...
>>> }
>>>
>>> @Stateless()
>>> public class SimpleBean
>>> implements SimpleLocal{
>>> ...
>>> }
>>>
>>> The POJO:
>>>
>>> public class SimplePOJO {
>>>
>>> // .ctor
>>> public SimplePOJO (){
>>> Context c = new InitialContext();
>>> SimpleLocal myBean =
>>> (SimpleBean)c.lookup("java:comp/env/ejb/SimpleBean");
>>> }
>>>
>>> }
>>>
>>> I tried use my SimpleBean from a servlet using annotation @EJB and here
>>> works fine.
>>> But in my SimplePOJO constructor I get a
>>> javax.naming.NameNotFoundException.
>>>
>>> Is there something wrong in my code?
>>> Do I need a .xml descriptor?
>>>
>>> Thank you,
>>> Angelo
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>>
>>
>
>