users@glassfish.java.net

Re: EJB3 NameNotFoundException with simple local sample

From: angelogeminiani <angelo.geminiani_at_gmail.com>
Date: Thu, 20 Sep 2007 06:29:38 -0700 (PDT)

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
>
>
>

-- 
View this message in context: http://www.nabble.com/EJB3-NameNotFoundException-with-simple-local-sample-tf4486501.html#a12797119
Sent from the java.net - glassfish users mailing list archive at Nabble.com.