tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hynek <>
Subject EntityManager/EntityManagerFactory not injected to CDI bean
Date Wed, 08 Feb 2017 12:05:21 GMT
Hello all!

I have an issue with injecting EntityManagerFactory (or EntityManager) into
a CDI managed bean.

My application is structured such that I have a root app.ear containing
persistence.jar and rest.war. When deployed to TomEE 7.0.2 it initialized
and starts up OK (no errors in the logs). persistence.jar defines my JPA
entities, persistence.xml with persistent unit, a service class referencing
EntityManager and providing business methods to the servlet classes in

EntityManager is being resolved with a CDI bean below. The motivation is,
besides to have a bit more flexibility with CDI, to be able to explicitly
drive the life time of the produced EntityManager instances:

And the service consuming the produced EntityManager:

Both classes above are packaged in peristence.jar.

Then in rest.war the service is consumed as follows:

As I have mentioned the ear deploys OK with no apparent errors. But when a
request comes to RestServer *the app fails with a NullPointerException
inside of EntityManagerProducer.newEntityManager() due to emFactory being
null, it is never set*.

Interesting to note, when I remove the @Inject annotation of Service.em and
use @PersistentContext directly there, the entity manager is properly
injected into the Service EJB and the REST request passes OK.

Any help is greatly appreciated!


View this message in context:
Sent from the TomEE Users mailing list archive at

View raw message