[ 
https://issues.apache.org/jira/browse/TOMEE-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13486000#comment-13486000
 ] 

Donatas Ciuksys commented on TOMEE-508:
---------------------------------------

I'll try to justify (or at least defend) the possibility to use Extended 
EntityManager outside of its home Stateful EJB: from JPA specification:

-----------------------------------------------
3.3 Persistence Context Lifetime
...
When an extended persistence context is used, the extended persistence context 
exists from the time the
EntityManager instance is created until it is closed. This persistence context 
might span multiple transactions
and non-transactional invocations of the EntityManager. A container-managed 
extended persistence
context is enlisted in the current transaction when *the EntityManager is 
invoked in the scope of
that transaction* or when the stateful session bean to which the extended 
persistence context is bound is
invoked in the scope of that transaction.
-----------------------------------------------

The first clause in the last sentence presumes the case when EntityManager was 
accessed somehow without accessing Stateful bean itself.
And yes, of course, as all powerfull things, this might easily be abused and 
give unintented & wrong results (if used unwisely).

Having all this in mind, and provided with powerful CDI scoped injection 
facility, one would really dare to inject extended EM :) I just guess that when 
this doesn't work out, one assumes her/his poor understanding of CDI/EJB and 
tries alternative ways (simpler, but requiring more programming).
                
> EntityManager dependency considered not passivation capable (CDI spec 
> violation)
> --------------------------------------------------------------------------------
>
>                 Key: TOMEE-508
>                 URL: https://issues.apache.org/jira/browse/TOMEE-508
>             Project: TomEE
>          Issue Type: Bug
>    Affects Versions: 1.5.0, 1.5.1
>         Environment: Windows 7 x64; jdk1.7.0_09 32 bit; 
> apache-tomee-1.5.1-20121026.064316-51-webprofile.zip
>            Reporter: Donatas Ciuksys
>            Priority: Blocker
>
> 1. Create class EntityManagerProducer:
> @SessionScoped
> @Stateful
> public class EntityManagerProducer implements Serializable {
>     
>     @PersistenceContext(type=PersistenceContextType.EXTENDED)
>     private EntityManager em;
>     
>     @Produces
>     public EntityManager getEntityManager() {
>         return em;
>     }
> }
> 2. Create injection client:
> @Named
> @SessionScoped
> @Stateful
> public class A implements Serializable  {
>     
>     @Inject
>     private EntityManager em;
>     public String getDelegateClassName() {
>         return em.getDelegate().getClass().getCanonicalName();
>     }
>     
> }
> 3. Create JSF page and try to call getDelegateClassName():
>     <h:body>
>         EntityManager is open: #{a.delegateClassName}
>     </h:body>
> 4. Try to deploy the application to tomee - observe error message:
> Caused by: org.apache.openejb.OpenEJBRuntimeException: 
> org.apache.webbeans.exception.WebBeansConfigurationException: Passivation 
> capable beans must satisfy passivation capable dependencies. Bean : A, 
> Name:a, WebBeans Type:ENTERPRISE, API Types:[java.lang.Object,beans.A], 
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]
>  does not satisfy. Details about the Injection-point: Field Injection Point, 
> field name :  em, Bean Owner : [A, Name:a, WebBeans Type:ENTERPRISE, API 
> Types:[java.lang.Object,beans.A], 
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
>       at 
> org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:323)
>       at 
> org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:150)
>       ... 48 more
> Caused by: org.apache.webbeans.exception.WebBeansConfigurationException: 
> Passivation capable beans must satisfy passivation capable dependencies. Bean 
> : A, Name:a, WebBeans Type:ENTERPRISE, API Types:[java.lang.Object,beans.A], 
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]
>  does not satisfy. Details about the Injection-point: Field Injection Point, 
> field name :  em, Bean Owner : [A, Name:a, WebBeans Type:ENTERPRISE, API 
> Types:[java.lang.Object,beans.A], 
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
>       at 
> org.apache.webbeans.component.AbstractOwbBean.validatePassivationDependencies(AbstractOwbBean.java:695)
>       at 
> org.apache.webbeans.component.AbstractInjectionTargetBean.validatePassivationDependencies(AbstractInjectionTargetBean.java:595)
>       at 
> org.apache.openejb.cdi.BeansDeployer.checkPassivationScope(BeansDeployer.java:414)
>       at org.apache.openejb.cdi.BeansDeployer.validate(BeansDeployer.java:260)
>       at 
> org.apache.openejb.cdi.BeansDeployer.validateInjectionPoints(BeansDeployer.java:222)
>       at 
> org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:280)
>       ... 49 more
> ---------------------------------
> I think this is CDI specification violation - page 3 of CDI specification 
> contains following example:
> @SessionScoped @Model
> public class Login implements Serializable {
>     @Inject Credentials credentials;
>     @Inject @Users EntityManager userDatabase;
> ...

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to