tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hynek <hynek.cih...@gmail.com>
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
rest.war:

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!

Thanks,
Hynek




--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/EntityManager-EntityManagerFactory-not-injected-to-CDI-bean-tp4681031.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Mime
View raw message