8 Replies Latest reply on Aug 18, 2009 11:41 PM by pmuir

    understand ValidateBean

    diegocoronel

      Hi Folks,


      i was playing with some webBeans possibilities and i got this problem:

      I did a provider like this:




      public class PersistenceProvider implements Serializable {
           private static final long serialVersionUID = 1L;
       
           @Produces  @PersistenceContext @ConversationScoped @ManualFlushMode @Database
           private EntityManagerSerializable entityManager;



      and i got this error:




      11:05:32,124 ERROR [AbstractKernelController] Error installing to Start: name=vfsfile:/C:/trabalho_diego/jboss-5.1.0.GA/server/web/deploy/HelloWebBeans.ear/_WebBeansBootstrapBean state=Create
      javax.enterprise.inject.UnproxyableResolutionException: Normal scoped bean Annotated Conversation scoped unnamed producer field bean [com.fpf.provider.PersistenceProvider] for class type [com.fpf.provider.EntityManagerSerializable] API types [class java.lang.Object, interface java.io.Serializable, interface javax.persistence.EntityManager, class org.hibernate.ejb.AbstractEntityManagerImpl, class com.fpf.provider.EntityManagerSerializable, interface org.hibernate.ejb.HibernateEntityManager, interface org.hibernate.ejb.HibernateEntityManagerImplementor, class org.hibernate.ejb.EntityManagerImpl], binding types [@javax.enterprise.inject.Any(), @com.fpf.provider.Database()] is not proxyable
           at org.jboss.webbeans.Validator.validateBean(Validator.java:81)



      so, it says that my bean isnt proxyable AND is normal scoped, but shouldnt it be considered @ConversationScoped? so, isnt my entityManager annotations considered for validations ? because if i change @ConversationScoped annotation to my @Database it works because now the validation didnt throw exception:


          


       boolean normalScoped = beanManager.getServices().get(MetaAnnotationStore.class).getScopeModel(bean.getScopeType()).isNormal();
            if (normalScoped && !Beans.isBeanProxyable(bean))
            {
               throw new UnproxyableResolutionException("Normal scoped bean " + bean + " is not proxyable");
            }



      so, is it expected?



        • 1. Re: understand ValidateBean
          nickarls

          Conversation scope is a normal scope. Remote the annotation and it will fall back to dependent scope and the proxy is no longer required.

          • 2. Re: understand ValidateBean
            diegocoronel

            Hi Nicklas,


            ty for explanation, but i cant understand why my entityManager is considered Normal Scoped when my @Conversation scoped is declared like that:



            @Produces  @PersistenceContext @ConversationScoped @ManualFlushMode @Database
                 private EntityManagerSerializable entityManager;



            and is Dependent scoped when my @ConversationScoped is declared inside my @Database annotation.


            I suppose that in these 2 cases it should be NormalScoped because my @Produces will create same entityManager in ConversationScope. Can you explain me this pls ?


            ty, sry about english.

            • 3. Re: understand ValidateBean
              nickarls

              So @Database is a stereotype and not a binding type? (hopefully IDE tooling will do highlighting etc on these as they're impossible to keep apart from plain text) Post the code for it.

              • 4. Re: understand ValidateBean
                diegocoronel

                hi Nicklas,


                so, i was trying a binding type conversationScoped...




                @Target( { METHOD, FIELD, TYPE, PARAMETER } )
                @Retention( RUNTIME )
                @ConversationScoped
                @BindingType
                public @interface Database {
                
                }
                


                and


                @Produces  @PersistenceContext @ManualFlushMode @Database
                     private EntityManagerSerializable entityManager;





                works, but




                @Target( { METHOD, FIELD, TYPE, PARAMETER } )
                @Retention( RUNTIME )
                @BindingType
                public @interface Database {
                
                }



                and


                @Produces  @PersistenceContext @ConversationScoped @ManualFlushMode @Database
                     private EntityManagerSerializable entityManager;



                doesnt work, so, i cant understand why these 2 ways to make a @Produces dont generate same behaviour. why in these 2 cases the result isnt entityManager in conversation context with @Database binding type?


                ty

                • 5. Re: understand ValidateBean
                  nickarls

                  your @Database is a binding type, it can't carry a @ConversationScoped (well, you can put it there and it will compile but it won't do anything), stereotypes was used for that earlier, have to check what they are called nowadays ;-)

                  • 6. Re: understand ValidateBean
                    nickarls

                    Yep, still stereotypes so my original claim stands

                    • 7. Re: understand ValidateBean
                      pmuir

                      This is basically a bug, Web Beans should automatically produce a passivation capable bean in this case.


                      Note that the spec doesn't guarantee that a conversation scoped resource is possible.


                      • 8. Re: understand ValidateBean
                        pmuir