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

Mark Struberg (JIRA) issues at jboss.org
Sun May 3 06:55:45 EDT 2015


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

Mark Struberg edited comment on CDI-520 at 5/3/15 6:55 AM:
-----------------------------------------------------------

a.) there is not _the_ EntityManager, there are in fact a few of them. E.g. the 'native' one from JPA vs the 'Facade' you get when using @PersistenceContext in managed beans. The later is really just a facade which delegates to the 'real' EM which he gets from the TransactionSynchronizationRegistry [1] (This is why the getDelegate() method exists btw). And the point is that this mapping gets basically maintained by the EJB container.

b.) The EJB spec clearly says in chapter 13, esp 13.2.5 'Container-Managed Demarcation' and 13.3.3 'Enterprise Beans Using Bean-Managed Transaction Demarcation' that container-managed and bean-managed transactions are only defined for 'enterprise beans'. Please note that 'enterprise beans' are ONLY javax.ejb beans and _not_ the rest which is subsummed under the more generic term 'managed beans'.

c.) there is no other spec which defines how transaction demarcation works for EE 'Managed Beans' (btw there are many different 'Managed Beans' in EE still...)
*edit* To make this more clear: a few specs define that you can inject an EntityManager into managed beans. But only the EJB spec defines how that EntityManager gets instrumented. And it only defines the behaviour for EJBs itself.

I'm not saying this for fun but because I know a few containers which will blow up if you access a @PersistenceContext EntityManager without being in the call frame of any EJB. It might work for a few, but not that: "You are now leaving the portable sector" :D

Feel free to get this fixed/clarified for EE-8 :)

[1] http://docs.oracle.com/javaee/6/api/javax/transaction/TransactionSynchronizationRegistry.html


was (Author: struberg):
a.) there is not _the_ EntityManager, there are in fact a few of them. E.g. the 'native' one from JPA vs the 'Facade' you get when using @PersistenceContext in EJBs. The later is really just a facade which delegates to the 'real' EM which he gets from the TransactionSynchronizationRegistry [1] (This is why the getDelegate() method exists btw). And the point is that this mapping gets basically maintained by the EJB container.

b.) The EJB spec clearly says in chapter 13, esp 13.2.5 'Container-Managed Demarcation' and 13.3.3 'Enterprise Beans Using Bean-Managed Transaction Demarcation' that container-managed and bean-managed transactions are only defined for 'enterprise beans'. Please note that 'enterprise beans' are ONLY javax.ejb beans and _not_ the rest which is subsummed under the more generic term 'managed beans'.

c.) there is no other spec which defines how transaction demarcation works for EE 'Managed Beans' (btw there are many different 'Managed Beans' in EE still...)

I'm not saying this for fun but because I know a few containers which will blow up if you access a @PersistenceContext EntityManager without being in the call frame of any EJB. It might work for a few, but not that: "You are now leaving the portable sector" :D

Feel free to get this fixed/clarified for EE-8 :)

[1] http://docs.oracle.com/javaee/6/api/javax/transaction/TransactionSynchronizationRegistry.html

> 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