tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: EntityManager/EntityManagerFactory not injected to CDI bean
Date Wed, 08 Feb 2017 12:58:31 GMT
Hi

can be that a jar is not used by cdi cause of anything, can you start with
the system property openejb.cdi.debug=true to check the class is scanned.

Also is your unit a resource local one or jta one?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-02-08 13:05 GMT+01:00 Hynek <hynek.cihlar@gmail.com>:

> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message