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

ROUMEAS Micaël <[email protected]> Tue, 01 Mar 2011 16:24:42 +0000
Newsgroups gmane.comp.java.objectweb.jonas
Message-ID <[email protected]>
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.
>>
>>
>