1 2 Previous Next 16 Replies Latest reply on Jan 6, 2010 6:59 PM by bleathem

    Serialization Problems

    diegocoronel

      Hi, im trying to make some examples with weld/JSF2/JPA2 and i am getting some problems with serialization...


      I want a stateless session DAO and i dont know how to resolve the problem




      @Stateless
      public class UsuarioDAO extends PostgresDAO<Usuario, Integer> implements Serializable {
      
           private static final long serialVersionUID = 1L;
      
           public Usuario getUsuario( String login, String password ) {
                CriteriaBuilder qb = getCriteriaBuilder();
                CriteriaQuery<Usuario> criteria = qb.createQuery(Usuario.class);
                
                Root<Usuario> root = criteria.from(Usuario.class);
                
                criteria
                     .select(root)
                     .where( qb.equal( root.get( Usuario_.login ), login ) ,
                               qb.equal( root.get( Usuario_.password ), password ) );
                
                return entityManager.createQuery(criteria).getSingleResult();
           }




      public abstract class PostgresDAO <T, ID extends Serializable> {
      
           @Inject @Database
           protected EntityManager entityManager;
      
           @Inject 
           private EntityManagerFactory entityManagerFactory;
           
          protected CriteriaBuilder getCriteriaBuilder() {
              return entityManagerFactory.getCriteriaBuilder();
          }





      public class PersistenceProvider implements Serializable {
           private static final long serialVersionUID = 1L;
       
           @PersistenceContext( unitName = "HelloWebBeans" )
           private EntityManager entityManager;
      
           @PersistenceUnit( unitName = "HelloWebBeans" )
           private EntityManagerFactory emf;
      
           @Produces @ConversationScoped @Database 
           public EntityManager getEntityManager() {
                return entityManager;
           }
      
           @Produces @ConversationScoped 
           public EntityManagerFactory getEmf() {
                return emf;
           }
           
      }
      



      and i am  getting this error:



      SEVERE: Exception while loading the app
      org.glassfish.deployment.common.DeploymentException: The bean org.jboss.weld.bean-/C:/backup/diego/trabalho/glassfishv3_b73_nghtly/glassfish/domains/domain1/eclipseApps/HelloWebBeans/-ManagedBean-class com.fpf.web.security.login.Authenticator declares a passivating scope but has non-serializable dependency: org.jboss.weld.bean-/C:/backup/diego/trabalho/glassfishv3_b73_nghtly/glassfish/domains/domain1/eclipseApps/HelloWebBeans/-SessionBean-UsuarioDAO
           at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:169)
           at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:88)
           at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:239)
           at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:337)
           at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
           at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
           at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:362)
           at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:201)
           at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
           at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
           at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
           at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:789)
           at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:697)
           at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:952)
           at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:166)
           at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
           at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
           at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
           at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
           at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
           at java.lang.Thread.run(Thread.java:619)
      Caused by: org.jboss.weld.UnserializableDependencyException: The bean org.jboss.weld.bean-/C:/backup/diego/trabalho/glassfishv3_b73_nghtly/glassfish/domains/domain1/eclipseApps/HelloWebBeans/-ManagedBean-class com.fpf.web.security.login.Authenticator declares a passivating scope but has non-serializable dependency: org.jboss.weld.bean-/C:/backup/diego/trabalho/glassfishv3_b73_nghtly/glassfish/domains/domain1/eclipseApps/HelloWebBeans/-SessionBean-UsuarioDAO
           at org.jboss.weld.Validator.validateInjectionPointPassivationCapable(Validator.java:261)
           at org.jboss.weld.Validator.validateInjectionPoint(Validator.java:249)
           at org.jboss.weld.Validator.validateBean(Validator.java:80)
           at org.jboss.weld.Validator.validateRIBean(Validator.java:100)
           at org.jboss.weld.Validator.validateBeans(Validator.java:282)
           at org.jboss.weld.Validator.validateDeployment(Validator.java:268)
           at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:389)
           at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:166)
           ... 30 more
      
      



      so, how can i have stateless session bean that with entityManager field ?


      ty.








        • 1. Re: Serialization Problems
          nickarls

          SessionBean.isPassivationCapable says


             @Override
             public boolean isPassivationCapable()
             {
                return getEjbDescriptor().isStateful();
             }
          



          and that is what fails in validation so I think that's the problem. Not sure why the limitation is there.

          • 2. Re: Serialization Problems
            gavin.king

            Caused by: org.jboss.weld.UnserializableDependencyException: The bean org.jboss.weld.bean-... ManagedBean-class com.fpf.web.security.login.Authenticator declares a passivating scope but has non-serializable dependency: org.jboss.weld.bean-...-SessionBean-UsuarioDAO

            Looks like a bug to me. All session beans are passivation capable dependencies, according to 6.6.2 of the spec.


            We need Pete to tell us more.

            • 3. Re: Serialization Problems
              gavin.king

              Not sure why the limitation is there.

              There is a difference between passivation capable bean and passivation capable dependency. A stateless session bean is not passivation capable (it can't be serialized) but it is a passivation capable dependency. Read 6.6.

              • 4. Re: Serialization Problems
                andygibson.contact.andygibson.net

                I came across the same issue and created a simple test project to deploy on JBoss and Glassfish to demonstrate it. I ran into the problem by injecting a stateless EJB into a conversationally scoped non-EJB managed bean. It looks like the injection of a stateless EJB into a passivating scoped (session/conversation) bean triggers this problem in Glassfish. Stateful beans work fine and both ejb types work on JBoss 5.2. I'm using Glassfish build 71 and the modified Weld-osgi bundle roger sent me adding the conversational jsf view handler.


                The code is pretty straightforward, my simple bean receiving the ejb : 


                @Named
                @SessionScoped
                public class SimpleBean implements Serializable {
                
                     @Inject 
                     private StatelessLocal myStatelessBean;
                     
                     public String getMessage() {
                          return myStatelessBean.getText();
                     }
                }



                My Stateless EJB being injected :


                @Named
                @Stateless
                public class MyStatelessBean implements StatelessLocal, Serializable {
                
                     public String getText() {
                          return "this is the text from the stateless bean";
                     }
                }



                And my stateless EJB @Local interface :


                @Local
                public interface StatelessLocal {
                
                     String getText();
                }




                I have my test project with source that will re-produce the problem and I can go and file a JIRA with Glassfish with it if it is a Glassfish issue and not a Weld issue (works fine in JBoss, but I thought I'd double check).


                Also, does JBoss 5.20 Beta support EJB deployments in War files, or is it just deploying  them as managed beans and ignoring the @stateless annotations. I thought I read that JBoss does allow deploying EJBs in WAR files even outside of EJB 3.1.


                Cheers,


                Andy





                PS Here's the log and the exception


                WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context , because request parameters have already been read, or ServletRequest.getReader() has already been called
                INFO: Portable JNDI names for EJB MyStatelessBean : [java:global/fullweldapp/MyStatelessBean, java:global/fullweldapp/MyStatelessBean!org.weldejb.ejb.StatelessLocal]
                INFO: Instantiated an instance of org.hibernate.validation.engine.resolver.JPATraversableResolver.
                INFO: nullID: /C:/Dev/Servers/glassfish-v3-b71/glassfish/domains/domain1/applications/fullweldapp/ CLASSES: [class org.weldejb.bean.SimpleBean, class org.weldejb.ejb.MyStatelessBean, interface org.weldejb.ejb.StatelessLocal, class org.weldejb.model.Person]
                INFO: Initializing Mojarra 2.0.2 (FCS b01) for context '/fullweldapp'
                INFO: Loading application fullweldapp at /fullweldapp
                SEVERE: Exception while loading the app
                org.glassfish.deployment.common.DeploymentException: The bean org.jboss.weld.bean-/C:/Dev/Servers/glassfish-v3-b71/glassfish/domains/domain1/applications/fullweldapp/-ManagedBean-class org.weldejb.bean.SimpleBean declares a passivating scope but has non-serializable dependency: org.jboss.weld.bean-/C:/Dev/Servers/glassfish-v3-b71/glassfish/domains/domain1/applications/fullweldapp/-SessionBean-MyStatelessBean
                        at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:169)
                        at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:88)
                        at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:239)
                        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:323)
                        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:169)
                        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
                        at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
                        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
                        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
                        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
                        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
                        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
                        at org.glassfish.admingui.common.util.LocalDeploymentFacility$LocalDFCommandRunner.run(LocalDeploymentFacility.java:138)
                        at org.glassfish.deployment.client.AbstractDeploymentFacility.deploy(AbstractDeploymentFacility.java:350)
                        at org.glassfish.admingui.common.util.DeployUtil.invokeDeploymentFacility(DeployUtil.java:89)
                        at org.glassfish.admingui.common.util.DeployUtil.deploy(DeployUtil.java:66)
                        at org.glassfish.admingui.common.handlers.DeploymentHandler.deploy(DeploymentHandler.java:186)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at com.sun.jsftemplating.layout.descriptors.handler.Handler.invoke(Handler.java:442)
                        at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:420)
                        at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:394)
                        at com.sun.jsftemplating.layout.event.CommandActionListener.invokeCommandHandlers(CommandActionListener.java:150)
                        at com.sun.jsftemplating.layout.event.CommandActionListener.processAction(CommandActionListener.java:98)
                        at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
                        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:772)
                        at javax.faces.component.UICommand.broadcast(UICommand.java:300)
                        at com.sun.webui.jsf.component.WebuiCommand.broadcast(WebuiCommand.java:160)
                        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:774)
                        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1266)
                        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
                        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
                        at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:229)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
                        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
                        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
                        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
                        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
                        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
                        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
                        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
                        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
                        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:239)
                        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:789)
                        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:697)
                        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:952)
                        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:166)
                        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
                        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
                        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
                        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
                        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
                        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
                        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
                        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                        at java.lang.Thread.run(Thread.java:619)
                Caused by: org.jboss.weld.UnserializableDependencyException: The bean org.jboss.weld.bean-/C:/Dev/Servers/glassfish-v3-b71/glassfish/domains/domain1/applications/fullweldapp/-ManagedBean-class org.weldejb.bean.SimpleBean declares a passivating scope but has non-serializable dependency: org.jboss.weld.bean-/C:/Dev/Servers/glassfish-v3-b71/glassfish/domains/domain1/applications/fullweldapp/-SessionBean-MyStatelessBean
                        at org.jboss.weld.Validator.validateInjectionPointPassivationCapable(Validator.java:261)
                        at org.jboss.weld.Validator.validateInjectionPoint(Validator.java:249)
                        at org.jboss.weld.Validator.validateBean(Validator.java:80)
                        at org.jboss.weld.Validator.validateRIBean(Validator.java:100)
                        at org.jboss.weld.Validator.validateBeans(Validator.java:282)
                        at org.jboss.weld.Validator.validateDeployment(Validator.java:268)
                        at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:389)
                        at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:166)
                        ... 64 more

                • 5. Re: Serialization Problems
                  nickarls

                  I filed https://jira.jboss.org/jira/browse/WELD-290 yesterday, feel free to append the test case there

                  • 6. Re: Serialization Problems
                    andygibson.contact.andygibson.net

                    Hey Nicklas,


                    I'm not sure it is a Weld problem but a Glassfish deployment problem. I can only get my example to fail on Glassfish and it works fine with JBoss 5.20 Beta. I can't speak for the original poster, he may have problems on both since he has different code to mine, but I did see he was deploying on Glassfish also (see the glassfish weld deployer in his stack trace).


                    Regardless, I'll add the test case to the JIRA issue tomorrow (Tuesday) anyway,


                    Cheers,


                    Andy Gibson

                    • 7. Re: Serialization Problems
                      nickarls

                      Hmmm(tm)


                      Diego, could you show the Authenticator class?

                      • 8. Re: Serialization Problems
                        diegocoronel

                        Hi Nicklas,


                        Im at work now and my source is at home, tonight ill post Authenticator class.

                        • 9. Re: Serialization Problems
                          nickarls

                          And put that t-shirt on, this is a public place! ;-)

                          • 10. Re: Serialization Problems
                            andygibson.contact.andygibson.net

                            Here's the score so far, as usual, these things never go smoothly.


                            To completely remove the issue of whether EJBs in wars are being deployed in JBoss, I created an EAR project with an ejb and web module ao we know for sure the EJBs are discovered in JBoss. Problem is that the ear won't deploy in JBoss, I get a Missing ValidatorFactory attachment in deployment error when I try deploying it. The EAR deploys just fine in Glassfish, and the passivation/serialization error that was found still exists in the EAR deployment.


                            So, Glassfish obviously has a problem, the question is whether JBoss has it too, in which case it would probably be a Weld issue. It may be that with the WAR deployment JBoss is treating the EJB as a simple managed bean because it's not seeing the @Stateless annotation because it isn't looking for EJBs. It is treating the bean as a simple managed bean which will work, and will work in Glassfish too.


                            Only problem is that I can't test that theory beacuse I can't get the project with separate EJBs deployed on JBoss to test it.


                            However Nicklas, I think your original assessment (in the JIRA) may be correct, there is no distinction being made between a proxiable bean and an injected proxiable bean in Weld. For this reason, I think it may be a weld issue and not a Glassfish issue (we just can't prove it yet by getting the EAR project to fail for the same reason in JBoss).


                            I have uploaded my new EAR project that demonstrates the problem on Glassfish and could be used to test the problem on JBoss if the deployment issue is resolved.


                            Cheers,


                            Andy Gibson



                            • 11. Re: Serialization Problems
                              diegocoronel

                              Heres my authenticator class




                              @Named
                              @SessionScoped
                              public class Authenticator implements Serializable {
                                   private static final long serialVersionUID = 1L;
                                   
                                   @Inject @Credentials
                                   private CredentialsImpl credentials;
                              
                                   private String login;
                                   
                                   @Inject
                                   private Conversation conversation;
                                   
                                   @Inject
                                   private UsuarioDAO usuarioDAO;
                                   
                                   public Authenticator() {
                                        System.out.println( "Authenticator inicializado" );
                                   }
                                   
                                   public String authenticate() {
                                        if ( isLogged() ) {
                                             conversation.begin();
                                             return "ATIVO";
                                        }
                                        return "tryAgain"; 
                                   }
                                   
                                   public boolean isLogged() {
                                        if ( login != null  ) {
                                             return true;
                                        } else {
                                             if ( usuarioDAO.getUsuario( credentials.getLogin(), credentials.getPassword() ) != null ) {
                                                  login = credentials.getLogin();
                                                  return true;
                                             } 
                                        }
                                        return false;
                                   }
                                   
                                   public @Produces @LoggedUser Usuario loggedUser() {
                                        if ( isLogged() ) {
                                             return usuarioDAO.getUsuarioByLogin(login);
                                        }
                                        return null;
                                   }
                              }



                              • 12. Re: Serialization Problems
                                nickarls

                                Hmmm, nothing stange there. And Andy said it works on JBoss 5.2 (which I think it shouldn't by looking at the code). Have to see what Pete has to say when gets de-devoxxed

                                • 13. Re: Serialization Problems
                                  andygibson.contact.andygibson.net

                                  Hey Nicklas, Just to clarify, I think it will probably work on JBoss if the EJBs are being deployed in a war file (as in jee6) and JBoss is treating them as regular managed beans and not seeing them as EJBs (as I had my first sample). It remains to be seen whether it will work on JBoss if the EJBs are deployed as EJBs.  Unless of course Jboss is picking up EJBs in war files (as I thought I had read once upon a time). Diego hasn't mentioned what App Servers/versions he has tried it with and how he is deploying his app.


                                  Ahh, Pete is at Devoxx, I was wondering where he had got to and why he hadn't jumped in with comments.


                                  Cheers,


                                  Andy

                                  • 14. Re: Serialization Problems
                                    diegocoronel

                                    Diego hasn't mentioned what App Servers/versions he has tried it with and how he is deploying his app.

                                    Hi Andy, im using GlassFish V3 b73-2009-11-13 and deploying my application as WAR.

                                    1 2 Previous Next