[cdi-dev] [JBoss JIRA] (CDI-520) 3.6. Java EE components

Antoine Sabot-Durand (JIRA) issues at jboss.org
Wed Apr 29 10:56:45 EDT 2015


    [ https://issues.jboss.org/browse/CDI-520?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13063950#comment-13063950 ] 

Antoine Sabot-Durand commented on CDI-520:
------------------------------------------

If you're interested by relations between CDI and EntityManager, you are reading the wrong section.
Section 3.6 deals with Java Components like:

* Servlet,
* Interceptor,
* JPA, Entity Listener,
* etc... (see table EE5.1 in Java EE 7 spec to have the complete list)

These components support injecting CDI beans but are not recommended  to be injected or to define producers, disposers or observer methods.
I agree that the sentence is not very clear.

Regarding your needs, you have to study section [3.7 Resources|http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#resources] since EntityManager is eligible to this notion of resources.

As you can read in this part 

{quote}
The container is not required to support resources with scope other than @Dependent. Portable applications should not define resources with any scope other than @Dependent.
{quote}

so you should try to put a scope on your produced `EntityManager`... What would be your use case anyway?


> 3.6. Java EE components
> -----------------------
>
>                 Key: CDI-520
>                 URL: https://issues.jboss.org/browse/CDI-520
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Java EE integration
>    Affects Versions: 1.1.Final
>            Reporter: Martin Andersson
>             Fix For: TBD
>
>
> I don't understand this text:
> "The instance used by the container to service an invocation of a Java EE component will not be the same instance obtained when using @Inject, instantiated by the container to invoke a producer method, observer method or disposer method, or instantiated by the container to access the value of a producer field."
> More specifically, I am trying to understand how we can use CDI to put a scope on {{EntityManager}} whose life cycle is rather undefined by JPA. I see that the specification use an example of a {{@Disposes}} method to close a container-managed entity manager which throw {{IllegalStateException}} in the disposer (!). Anyways, trying to solve this puzzle has led me to the paragraph quoted previously, of which I understand nothing to be honest.
> My research about the "CDI managed container-managed entity manager" continues. As of now, the example is flawed and a container-managed entity manager remains open after the disposer method. Anyways, I might open up a separate ticket for that.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the cdi-dev mailing list