NullPointerException when acquiring injected EntityManager in TomEE 1.7.1

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NullPointerException when acquiring injected EntityManager in TomEE 1.7.1

kerickson
I have an EJB class annotated  @Singleton and @Startup.
This class in turn contains an @Inject-ed EJB that is @Stateless, and this stateless EJB has a @Persistence EntityManager.

I'm finding that, when my startup code runs and calls into the stateless, its EntityManager is still null (see attached log). This happens under TomEE 1.7.0 too so I don't think it's a regression. But the exact same code was working for me once upon a time on the same system (with the same java JDK as well) so I'm not sure what's going on. If I don't use @Startup at all, there's never any issue reaching the injected EntityManager. Is there any reason that CDI would not have been ready by the time a stateless singleton would be able to run?

I'm using hibernate as a provider rather than openJPA, and it works fine until I use this arrangement.

Using windows 10, Java 8, JDK oracle 201.

Thanks,
-Kean


fail.txt (19K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException when acquiring injected EntityManager in TomEE 1.7.1

kerickson
 https://tomee.apache.org/examples/dynamic-datasource-routing.html

As a more concise example, the code here using a @Startup @Singleton with a
@PersistenceContext isn't working for me, it results in the entity manager
being null when provided a correct unitName and a proper entity to fetch. I
know that example is using OpenJPA and not hibernate,  I'm wondering if I'm
missing something or if this is a bug.

On Wed, Jul 24, 2019 at 4:07 PM Kean Erickson <[hidden email]>
wrote:

> I have an EJB class annotated  @Singleton and @Startup.
> This class in turn contains an @Inject-ed EJB that is @Stateless, and this
> stateless EJB has a @Persistence EntityManager.
>
> I'm finding that, when my startup code runs and calls into the stateless,
> its EntityManager is still null (see attached log). This happens under
> TomEE 1.7.0 too so I don't think it's a regression. But the exact same code
> was working for me once upon a time on the same system (with the same java
> JDK as well) so I'm not sure what's going on. If I don't use @Startup at
> all, there's never any issue reaching the injected EntityManager. Is there
> any reason that CDI would not have been ready by the time a stateless
> singleton would be able to run?
>
> I'm using hibernate as a provider rather than openJPA, and it works fine
> until I use this arrangement.
>
> Using windows 10, Java 8, JDK oracle 201.
>
> Thanks,
> -Kean
>
>