1 2 Previous Next 18 Replies Latest reply on Sep 1, 2010 3:23 AM by nickarls

    passivating scope must be passivation capable and bean is not proxyable

    nimo22

      I have this bean:





      import java.util.List;
      import javax.annotation.PostConstruct;
      import javax.annotation.PreDestroy;
      import javax.enterprise.context.SessionScoped;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.inject.Inject;
      import javax.inject.Named;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.slf4j.Logger;
      
      
      @SessionScoped @Named
      public class MyBean{
      
      @Inject private Logger log;     
      @PersistenceContext EntityManager entityManager;
      
      
      @PostConstruct
      public void initialize()
      {       
      log.info("@PostConstruct");
      log.info("{} was created.", this.getClass().getSimpleName());
      }
      
              
      @PreDestroy
      public void preDestroy()
      {
      log.info("@PreDestroy");
      log.info("{} was destroyed.", this.getClass().getSimpleName());
      }
      
      ..
      
      }




      and it returns this error:



      WELD-000072 Managed bean declaring a passivating scope must be passivation capable.
      Bean:  org.jboss.weld.bean-flat-ManagedBean-class com.MyBean




      The first question is:



      Does MyBean declares a passivating scope? Where? How can I undeclare it?


      I have not explicitly declared


      @NormalScope(passivating=true)




      According to JSR-299-Specification chapter 6.6.3. Passivating scopes:




      For example, the built-in session and conversation scopes defined in Section 6.7, “Context management for built-in
      scopes” are passivating scopes. No other built-in scopes are passivating scopes.


      So MyBean is SessionScoped, hence it implicitly declares


      @NormalScope(passivating=true)



      Am I right?


      And so I have to implement Serializable for all these kinds of beans:




      • sessionScoped ManagedBeans

      • conversationScoped ManagedBeans

      • statefull (EJB)SessionBeans





      Am I right?





      The second question is:





      After that deployement error, I have changed MyBean to implement Serializable:



      @SessionScoped @Named
      public class MyBean{
      
      implements Serializable{
      
      private static final long serialVersionUID = -2564031884483676327L;
      ..}



      And another deployement-error is coming:


      org.jboss.weld.exceptions.UnproxyableResolutionException: 
      WELD-001400 Normal scoped bean org.jboss.weld.bean-flat-ManagedBean-class 
      com.MyBean is not proxyable



      You see, MyBean is really a simple bean and CDI returns one error to another.


      What is wrong?



      I am using JBOSS 6 M4, its actual CDI-Implementation, JPA 2, JSF 2.



        • 1. Re: passivating scope must be passivation capable and bean is not proxyable
          nickarls

          nimo mayr wrote on Aug 31, 2010 04:26:

          So MyBean is SessionScoped, hence it implicitly declares

          @NormalScope(passivating=true)



          Am I right?


          yes



          nimo mayr wrote on Aug 31, 2010 04:26:

          And so I have to implement Serializable for all these kinds of beans:



          • sessionScoped ManagedBeans

          • conversationScoped ManagedBeans

          • statefull (EJB)SessionBeans






          • yes

          • yes

          • no (they already are)




          Am I right?




          nimo mayr wrote on Aug 31, 2010 04:26:

          What is wrong?


          No no-args constructor

          • 2. Re: passivating scope must be passivation capable and bean is not proxyable
            nimo22

            Gosh, you are so right:)


            from



            is not proxyable

            how do you derive that I missed a no-args constructor - from the source code?


            I have the source-code of cdi but cannot find the clause where jboss.weld.exceptions.UnproxyableResolutionException is thrown.




            • 3. Re: passivating scope must be passivation capable and bean is not proxyable
              nimo22

              I have a class Pojo(which itself has no scope and it is purley an object without any cdi-annotations):



              public class Pojo{
              
              .
              
              }




              Then I have a class MyBean which injects a (new) instance of POJO:


              @SessionScoped @Named
              public class MyBean implements Serializable{
              
              @Inject     private POJO pojo;
              
              ..
              }




              I get this error:




              org.jboss.weld.exceptions.UnserializableDependencyException: WELD-001413 The bean 
              org.jboss.weld.bean-flat-ManagedBean-class com.MyBean declares passivating scope but 
              has non-serializable dependency org.jboss.weld.bean-flat-ManagedBean-class com.Pojo




              So I have to implement Serializable for all of my Objects which are only pojos ?? Am I right? (That is annoying!)




              public class Pojo implements Serializable{
              
              .
              
              }


              • 4. Re: passivating scope must be passivation capable and bean is not proxyable
                nickarls

                nimo mayr wrote on Aug 31, 2010 07:04:

                how do you derive that I missed a no-args constructor - from the source code?

                I have the source-code of cdi but cannot find the clause where jboss.weld.exceptions.UnproxyableResolutionException is thrown.


                It's mostly in the Validator


                There will be improvements to the messages. And non-portable extensions that bypass this requirement.

                • 5. Re: passivating scope must be passivation capable and bean is not proxyable
                  nickarls

                  nimo mayr wrote on Aug 31, 2010 07:32:


                  So I have to implement Serializable for all of my Objects which are only pojos ?? Am I right? (That is annoying!)


                  Yes (at least for deps of passivating beans) ;-)


                  (blame Java and not CDI)

                  • 6. Re: passivating scope must be passivation capable and bean is not proxyable
                    nimo22


                    blame Java and not CDI

                    When injecting pojo in sessionscoped-bean, then pojo inherits this scope,
                    and that is the reason, why I am forced to implement Serializable for my pojo
                    (even when my pojo is not annotated with sessionscoped), am I right?



                    In Seam 2, I do not need to implement Serializable for common Objects which are included in Session-Beans!


                    When not using CDI to inject my POJO, then the deployement-error does not occur:


                    @SessionScoped @Named
                    public class MyBean implements Serializable{
                    
                    
                    // I only want to have a new instance of pojo
                    // so why I am forced to CHANGE my class pojo and implement serializable
                    private POJO pojo;
                    
                    public MyBean(POJO pojo)
                    {
                    this.pojo= pojo;
                    }
                    }



                    Imagine I have 100 of pojos which are not session-scoped (or conversation-scoped), I only can make use of these pojos in sessionscoped-cdi, if I implement Serializable for all those classes??? What about performance, what about intrusion?

                    • 7. Re: passivating scope must be passivation capable and bean is not proxyable
                      nimo22

                      The JSR-299 Specification says 6.6.3. Passivating scopes:



                      I have to implement Serializable for all these kinds of beans:




                      • sessionScoped ManagedBeans

                      • conversationScoped ManagedBeans



                      But a pojo is neither sessionScoped ManagedBeans nor conversationScoped ManagedBeans (so it is not passivation capable). It is not a managedBean as no scope was declared. The Specifiaction says nothing about the fact, that I need to implement Serializable for those kind of classes, too. I have thought, that injecting these pojos in session-scoped beans (wich implements Serializable ) is sufficient.

                      • 8. Re: passivating scope must be passivation capable and bean is not proxyable
                        asiandub



                        When injecting pojo in sessionscoped-bean, then pojo inherits this scope, and that is the reason, why I am forced to implement Serializable for my pojo (even when my pojo is not annotated with sessionscoped), am I right?



                        Technically: No.


                        When injecting a POJO into a session scoped bean, then the POJO will be dependent scoped.


                        The reason why you have to implement Serializable for the POJO is that the session scoped beans must not have any fields that are not serializable.




                        • 9. Re: passivating scope must be passivation capable and bean is not proxyable
                          asiandub

                          When not using CDI to inject my POJO, then the deployement-error does not occur.


                          Just had a little discussion about this question ;-)


                          I reckon the following is the reason for that:




                          1. If you don't use CDI, the property will simlpy not be scanned and validated by Weld.

                          2. If you every try to passivate the bean, you will pretty sure run into some kind of problem



                          Would be cool if someone could confirm this assumption.






                          • 10. Re: passivating scope must be passivation capable and bean is not proxyable
                            asiandub

                            Imagine I have 100 of pojos which are not session-scoped (or conversation-scoped), I only can make use of these pojos in sessionscoped-cdi, if I implement Serializable for all those classes??? What about performance, what about intrusion?

                            Serializable is a marker interface, so it will certainly not have implication on performance.


                            I don't know what you mean with intrusion?

                            • 11. Re: passivating scope must be passivation capable and bean is not proxyable
                              asiandub

                              But a pojo is neither sessionScoped ManagedBeans nor conversationScoped ManagedBeans (so it is not passivation capable). It is not a managedBean as no scope was declared. The Specifiaction says nothing about the fact, that I need to implement Serializable for those kind of classes, too. I have thought, that injecting these pojos in session-scoped beans (wich implements Serializable ) is sufficient.

                              Just to make it even more clear as here:


                              It's all good with the POJOs, the problem is the parent bean. No matter what, it can't be serialized if it has any non-serializable / non-transient members.




                              • 12. Re: passivating scope must be passivation capable and bean is not proxyable
                                swd847

                                nimo mayr wrote on Aug 31, 2010 08:28:


                                Imagine I have 100 of pojos which are not session-scoped (or conversation-scoped), I only can make use of these pojos in sessionscoped-cdi, if I implement Serializable for all those classes??? What about performance, what about intrusion?


                                Or you can mark the fields as transient, so they will not be serialized.

                                • 13. Re: passivating scope must be passivation capable and bean is not proxyable
                                  nickarls

                                  Or you can write a pimp-my-bean extension that vetoes it and replaces it with a proxy that implements serializable. But I would think that the pile of proxies would be more annoying...

                                  • 14. Re: passivating scope must be passivation capable and bean is not proxyable
                                    nimo22

                                    Hello Jan,


                                    thanks, now it is clear.



                                    When injecting a POJO into a session scoped bean, then the POJO will be dependent scoped.

                                    According to JSR-299 6.4:


                                    When a bean is declared to have @Dependent scope:
                                    
                                    = No injected instance of the bean is ever shared between multiple injection points.
                                    
                                    = Any instance of the bean injected into an object that is being created by 
                                    the container is bound to the lifecycle of the newly created object.



                                    In this case pojo dependents to sessionScoped-bean and inherits its lifecycle.




                                    Serializable is a marker interface, so it will certainly not have implication on performance.

                                    I am unsecure about the fact, that performance will not suffer, if these objects are (de)serialized.



                                    I don't know what you mean with intrusion?

                                    I have to change all my 100 objects only to fullfill the requirements of sessionScoped-Bean, if I want to inject it.


                                    Imagine sealed code - I cannot change these objects, but I want to inject it into SessionScoped Bean and make use of CDI.













                                    1 2 Previous Next