Re: null EntityManager while calling an EJB from an EJB.

ROUMEAS Micaël <[email protected]> Wed, 02 Mar 2011 19:43:50 +0000
Newsgroups gmane.comp.java.objectweb.jonas
Message-ID <[email protected]>
Hi Florent,


Sorry for the late reply.
My mistake wasn't an issue with JOnAS and / or Entity Manager injection 
as I was thinking.
It was a typo on a class name that I lazily copy and past on my example:

     @EJB Ejb2 otherEjb

As my local Interface is called "Ejb2I.class" for my bean "Ejb2.class".
I should have declared the following:

     @EJB Ejb2I otherEjb

Shame on me for this.

The file on the server was the attached one.


Regards,
M Roumeas.



2011/3/2 Florent BENOIT <[email protected] 
<mailto:[email protected]>>

         Hi Micaël,

    What was the mistake ? Maybe we should have a better check ?
    Also the file that you're providing is not the .class file


    Regards,

    Florent

    ROUMEAS Micaël wrote:
>     Hi Florent,
>
>     Thanks for your time.  your test was accurate as it allow me to
>     find out my mistake.
>
>     - I never used these log before. I did add the folowing lines to "
>     trace.properties " file:
>
>     *  org.ow2.easybeans.injection DEBUG
>       logger.org.ow2.easybeans.injection DEBUG
>
>       org.ow2.easybeans.enhancer.injection DEBUG
>       logger.org.ow2.easybeans.enhancer.injection DEBUG
>
>       org.ow2.easybeans.loader DEBUG
>       logger.org.ow2.easybeans.loader DEBUG*
>
>
>     - I'm was unsure of " logger " so I did add two lines for each
>     during the test.
>
>     - If I did it properly, it create a long file named (on my case):
>      org.ow2.easybeans.gen.invocationcontext.fr.bean.ws.Ejb1.EasyBeansInvocationContextImplbeanPreDestroy$generatedPREDESTROY39797.class
>
>     with some interesting lines there. Anyway I don't want to waste
>     your time just for some curiosity, but if there is some
>     documentation on it I'll be more than happy to learn a bit more
>     about it.
>
>
>     Thanks,
>     M Roumeas.
>
>
>     PS: attached file must give the log of the corrected test as I
>     didn't save the previous one.
>
>     Le 01/03/2011 16:49, Florent BENOIT a écrit :
>>         Hi,
>>
>>     Could you :
>>
>>     add @PersistenceContext on a setter method so you can check if
>>     the callback is called on your second EJB
>>     --> Log the injected PersistenceContext
>>
>>     Enable in JONAS_BASE/conf/trace.properties the logger for the
>>     following packages :
>>     -> org.ow2.easybeans.enhancer.injection
>>     -> org.ow2.easybeans.injection
>>
>>     And org.ow2.easybeans.loader
>>
>>
>>     And send me the log and the EJB2.class that should be present in
>>     your java.io.tmpdir (/tmp on Linux for Example)
>>
>>
>>     Regards,
>>
>>     Florent
>>
>>     ROUMEAS Micaël wrote:
>>>     Hi,
>>>
>>>     Thanks for this reply. Sadly, JOnAS 5.2.0.M4 did not solve my issue.
>>>
>>>     I did create a clear test sample but I still get the error.
>>>
>>>     ================================
>>>     ** Ejb1.java:
>>>
>>>     @EJB
>>>     Ejb2 otherEjb
>>>
>>>     method1( ) { otherEjb.method2( ); }
>>>
>>>     ================================
>>>     ** Ejb2.java:
>>>
>>>     @PersistenceContext( "PU-Name" )
>>>     private EntityManager em
>>>
>>>     method2( ) { em.find( MyClass.class, "findMe" ); }
>>>
>>>     ================================
>>>
>>>      - But I still have this NullPointerException when I call the
>>>     Ejb2 Stateless EJB:
>>>     AbsTransactionInterceptor.handleContextContainerTransaction :
>>>     Exception (not application exception) in business method
>>>     java.lang.NullPointerException
>>>
>>>
>>>     Is there anything special to do to inject entityManager ?
>>>     @PersistenceContext
>>>
>>>     or even
>>>     @PersistenceContext( "PU-Name" )
>>>
>>>     both work only in my 1st EJB.
>>>
>>>     Thanks for your time,
>>>     M Roumeas.
>>>
>>>     Le 01/03/2011 09:53, Hans J. Prueller a écrit :
>>>>     I cannot really help you but I would strongly suggest  that you
>>>>     upgrade to the latest 5.2M4 !
>>>>
>>>>     We are using 5.2M4 with same scenario as you do - several
>>>>     SLSB's "linked" to each other with @EJB annotations and all of
>>>>     the EJB's
>>>>     are having an injected entityManager with @PersistenceContext
>>>>     and this works pretty fine for us!
>>>>
>>>>     regards,
>>>>     Hans
>>>>
>>>>     Am Dienstag, den 01.03.2011, 09:46 +0000 schrieb ROUMEAS Micaël:
>>>>>     Hi there,
>>>>>
>>>>>     I'm actually using JOnAS 5.2.M3 and I have an issue with my EJBs.
>>>>>
>>>>>     I'm trying to use an EJB from another EJB, and so far the link "EJB to
>>>>>     EJB" is working properly.
>>>>>     My issue come when my second EJB try to use an EntityManager:
>>>>>           @PersistenceContext
>>>>>           private EntityManager em = null;
>>>>>
>>>>>           ...
>>>>>
>>>>>           em.find( myClass.class, "findMe" );
>>>>>
>>>>>
>>>>>     The "em" is null, JOnAS crash with a null pointer exception here.
>>>>>
>>>>>     I don't understand why. Because when I call my EJB from a servlet for
>>>>>     example, my entity manager "em" is not null.
>>>>>     "em" is null only if I call my EJB from another EJB from the same package.
>>>>>
>>>>>     Is there any reason for this ? Or do I miss understood some basics ?
>>>>>
>>>>>     I hope my problem is clearly explained.
>>>>>     Any clue or question will be more than welcome.
>>>>>
>>>>>     Thanks for your time,
>>>>>     M Roumeas.
>>>>>
>>>>>
>>>>>            
>>>>
>>>
>>
>
org.ow2.easybeans.gen.invocationcontext.fr.bean.ws.Ejb1.EasyBeansInvocationContextImplbeanPreDestroy$generatedPREDESTROY39797.class (application/octet-stream, 3.3 KB) - not displayed