7 Replies Latest reply on Mar 13, 2008 1:33 PM by Gavin Ellis

    s:convertEntity configuration

    Gavin Ellis Newbie

      The seam documenation states that in order to use the convertEntity tag the following configuration should be set in components.xml


      <component name="org.jboss.seam.ui.EntityConverter">
        <property name="session">#{hibernateSession}</property>
      </component>
      



      Could anyone tell me what this el expression is resolving? Is this the managed hibernate session i've also set up up in components.xml? e.g.


      <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
          <persistence:managed-hibernate-session name="session" auto-create="true"
                        session-factory-jndi-name="java:/hibernateSessionFactory"/>
      



      in which case do I need to change this to session? All attempts at configuring this component have resulted in a nullpointerexception


      SEVERE: Error Rendering View[/user.xhtml]
      java.lang.NullPointerException
              at org.jboss.seam.ui.converter.EntityConverterStore.getEntityManager(EntityConverterStore.java:81)
              at org.jboss.seam.ui.converter.EntityConverterStore.put(EntityConverterStore.java:60)
              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 org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:155)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:91)
              at org.jboss.seam.ui.converter.EntityConverterStore_$$_javassist_6.put(EntityConverterStore_$$_javassist_6.java)
              at org.jboss.seam.ui.converter.EntityConverter.getAsString(EntityConverter.java:67)
              at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:469)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:502)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:757)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:811)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:335)
              at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
              at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:279)
              at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:242)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
              at org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:186)
              at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166)
              at org.jboss.seam.ui.renderkit.ValidateAllRendererBase.doEncodeChildren(ValidateAllRendererBase.java:33)
              at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
              at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
              at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
              at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
              at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
              at org.jboss.web.tomcat.security.FormAuthValve.invoke(FormAuthValve.java:78)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:619)
      

        • 1. Re: s:convertEntity configuration
          Keith Naas Novice

          Gavin, the Seam wiki uses this behavior.


          From the components.xml


           <component name="restrictedEntityManager" auto-create="true" scope="CONVERSATION"
                         class="org.jboss.seam.wiki.core.dao.WikiManagedPersistenceContext">
                  <property name="entityManagerFactory">#{wikiEntityManagerFactory}</property>
                  <property name="persistenceUnitJndiName">java:/entityManagerFactories/wiki</property>
                  <property name="filters">
                      <value>#{accessLevelFilter}</value>
                  </property>
              </component>
              <!-- TODO: I want to reset the filter argument when a user logs in, so had to write my own SMPC, this is only
                         "safe" because a logged-in user means higher access privileges than before, so anything that was
                         cached in the SMPC before the filter argument is reset has to be still valid. We hope... 
              <persistence:managed-persistence-context name="restrictedEntityManager"
                                                auto-create="true"
                                                entity-manager-factory="#{wikiEntityManagerFactory}"
                                                persistence-unit-jndi-name="java:/entityManagerFactories/wiki">
                  <persistence:filters><value>#{accessLevelFilter}</value></persistence:filters>
              </persistence:managed-persistence-context>
              -->
          
              <persistence:managed-persistence-context name="entityManager"
                                                auto-create="true"
                                                entity-manager-factory="#{wikiEntityManagerFactory}"
                                                persistence-unit-jndi-name="java:/entityManagerFactories/wiki">
              </persistence:managed-persistence-context>
          
              <component name="restrictedEntityConverter" scope="CONVERSATION" precedence="20"
                         class="org.jboss.seam.ui.converter.EntityConverter">
                  <property name="entityManager">#{restrictedEntityManager}</property>
              </component>
          
              <component name="entityConverter" scope="CONVERSATION" precedence="20"
                         class="org.jboss.seam.ui.converter.EntityConverter">
                  <property name="entityManager">#{entityManager}</property>
              </component>
          
              <component name="nestedSetNodeWrapperRestrictedEntityConverter" scope="CONVERSATION" precedence="20"
                         class="org.jboss.seam.wiki.core.nestedset.ui.NestedSetNodeWrapperEntityConverter">
                  <property name="entityManager">#{restrictedEntityManager}</property>
              </component>
          
          

          • 2. Re: s:convertEntity configuration
            Gavin Ellis Newbie

            Thanks for this reply, Keith.


            This is a useful example for the EntityManager case, but I'm trying to set up the EntityConverter to work with managed hibernate sessions as per the examples in these docs http://docs.jboss.com/seam/latest/reference/en/html/controls.html


            Taking your example I'm guessing that the el expression in my case should be the name of the managed hibernate session e.g. session. This however doesn't seem to work and I get the NullPointerException listed above. Also, curiously, I've looked at the EntityConverter source code and this doesn't seem to have a hibernate session property nor a corresponding setSession setter. Debugging through the source code it's clear that the EntityManager nor session is being set, and when the EntityStoreConverter attempts to reference the EntityManager the NullPointerException is thrown:


            
            public EntityManager getEntityManager()
            
               {
            
                  if (!super.getEntityManager().isOpen())
            
                  {
            
                     super.setEntityManager(null);
            
                  }
            
                  return super.getEntityManager();
            
               }
            
            



            There is a jira on this very issue from a long time ago


            http://jira.jboss.org/jira/browse/JBSEAM-1242


            which suggests that the listed components made it into the main branch, although I cannot find a similarly named class in the seam jars. Can anyone verify whether or not these components exist?

            • 4. Re: s:convertEntity configuration
              Keith Naas Novice

              What version of seam are you using?

              • 5. Re: s:convertEntity configuration
                Pete Muir Master

                Umm, you've called your managed hibernate session session and tried to inject it using #{hibernateSession} - try using the same name.


                I improved the exception for 2.0.1 IIRC.

                • 6. Re: s:convertEntity configuration
                  Gavin Ellis Newbie

                  I was trying 2.0.0 but have upgraded to 2.0.1 with the same result. I've now switched back to using an EntityManager rather than hibernate session and making progress with this. I'm now experiencing this issue :-)


                  http://www.seamframework.org/Community/UnsupportedOperationExceptionInPersistentBagWhenUsingSconvertEntity

                  • 7. Re: s:convertEntity configuration
                    Gavin Ellis Newbie

                    Pete, I did try using session as mentioned above, but this didn't seem to help. I've now reverted back to using an EntityManager which seems to work. When I get a chance I'll have another go and report back the results to this thread...