4 Replies Latest reply on Dec 21, 2008 12:21 PM by Dirk Ho

    EntityManager closed because of s:convertEntity

    Dirk Ho Newbie

      Hello,


      after getting such great help in my first question, I would like to ask another problem, depending on a selectOneMenu.


      I use the following on my register.xhtml-page, so that people can select their title on registration:



      <h:selectOneMenu value="#{registerAction.anrede}">
           <s:convertEntity />
           <s:selectItems var="anrede" value="#{registerAction.anredeSelect()}" 
              label="#{anrede.anrede}" noSelectionLabel="Select Anrede..."/>
      </h:selectOneMenu>
      



      When I send the registration form, I always get the following exception:


      13:19:16,229 ERROR [viewhandler] Error Rendering View[/register.xhtml]
      java.lang.IllegalStateException: EntityManager is closed
           at org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:66)
           at org.hibernate.ejb.AbstractEntityManagerImpl.getDelegate(AbstractEntityManagerImpl.java:559)
           at org.jboss.seam.persistence.EntityManagerProxy.getDelegate(EntityManagerProxy.java:97)
           at org.jboss.seam.persistence.HibernatePersistenceProvider.getSession(HibernatePersistenceProvider.java:355)
           at org.jboss.seam.persistence.HibernatePersistenceProvider.getId(HibernatePersistenceProvider.java:163)
           at org.jboss.seam.framework.EntityIdentifier.<init>(EntityIdentifier.java:13)
           at org.jboss.seam.ui.JpaEntityLoader.createIdentifier(JpaEntityLoader.java:29)
           at org.jboss.seam.ui.AbstractEntityLoader.put(AbstractEntityLoader.java:46)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           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:28)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:40)
           at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:34)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
           at org.jboss.seam.ui.JpaEntityLoader_$$_javassist_1.put(JpaEntityLoader_$$_javassist_1.java)
           at org.jboss.seam.ui.EntityConverter.getAsString(EntityConverter.java:69)
           at org.jboss.seam.ui.converter.PrioritizableConverter.getAsString(PrioritizableConverter.java:67)
           at org.jboss.seam.ui.converter.ConverterChain.getAsString(ConverterChain.java:123)
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:448)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:480)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:768)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:828)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280)
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:946)
           at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
           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:204)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
           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.IdentityFilter.doFilter(IdentityFilter.java:38)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           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:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:150)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:379)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:506)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           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:73)
           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:182)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
           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.Http11AprProcessor.process(Http11AprProcessor.java:856)
           at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:566)
           at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
           at java.lang.Thread.run(Unknown Source)



      If I delte s:convertEntity out of my formular, I can submit it, but I only get a String as title.


      This is the registerAction.java


      @Stateless
      @Name("registerAction")
      // TODO @Restrict("#{not identity.loggedIn}")
      public class RegisterAction implements Register {
           
           @Logger
           Log log;
      
           private Anrede anrede;
           private ArrayList<Anrede> anreden;
           
           @EJB
           private Benutzerverwaltung bv;
           
           @PersistenceContext//(type = EXTENDED)
           private EntityManager em;
         
           @In
           private transient FacesContext facesContext;
         
           private String verify;
           
           public RegisterAction() {
      
           }
           
          public List<Anrede> anredeSelect() {
               ArrayList<Anrede> anreden = new ArrayList<Anrede>(bv.findAllAnreden());
               return anreden;
          }
      
         public String register() {
              log.info(anrede);
      
              return "";
         }
      
         public void setAnrede(String a) {
              this.anrede = a;
         }
         
         public String getAnrede() {
              return this.anrede;
         }
         
         public String getVerify()
         {
            return verify;
         }
      
         public void setVerify(String verify)
         {
            this.verify = verify;
         }



      I didn't change anything in components.xml or else where. I'm quiet new in Seam and hopefully someone can help me - explaining it in a simple way so that I can understand.


      Thanks and best regards,


      Dirk

        • 1. Re: EntityManager closed because of s:convertEntity
          Karthikeyan Chockalingam Newbie

          If you are using latest version like 2.1.1 of Seam you may have to place the below line in components.xml


          <ui:jpa-entity-loader entity-manager="#{em}" /> 



          For more details please refer section 32.1.2.2 of seam reference manual version 2.1.1.CR2


          As a note,I guess you may remove the instance variable anreden as it is not being used. (as in method anredeSelect the local anreden is returned)

          • 2. Re: EntityManager closed because of s:convertEntity
            Dirk Ho Newbie

            Hello


            thanks for your reply! I just downloaded Seam 2.1.1 CR2, unpacked it and renamed it to the name of my former Seam 2.1.0 installation. Afterwards, I changed my build.properties with the path to JBoss.


            If I start JBoss now, I get the message


            21:51:50,023 INFO  [ServletContextListener] Welcome to Seam 2.1.0.BETA1


            and later


            21:51:56,934 INFO  [ServletContextListener] Welcome to Seam 2.1.1.CR1


            While deploying my project I see


            21:55:17,756 INFO  [ServletContextListener] Welcome to Seam 2.1.0.BETA1


            But there is no Info that Seam 2.1.1 CR2 is used?!?!


            I also added your the line <ui:... /> in my components.xml, but it didn't work - perhaps some one can tell me, how I can tell JBoss to use Seam 2.1.1 CR2?


            I used this link for installation: http://www.jboss.org/jbossseam/gettingstarted/index.html


            Thanks and best regards,


            Dirk

            • 3. Re: EntityManager closed because of s:convertEntity
              Karthikeyan Chockalingam Newbie

              By chance, have you copied Seam 2.1.0BETA1 jars into lib folder of JBoss? Having two versions in classpath will lead to errors that do not instantiate the application.
              I use Maven (instead of seamgen structure). The key in configuring in Maven is that as JBoss comes with Hibernate and commons-xxx jars, please make their scope as provided.

              • 4. Re: EntityManager closed because of s:convertEntity
                Dirk Ho Newbie

                Hello Karthikeyan,


                thanks for your reply! I don't think, I copied any libs out of jboss-seam (2.1.0) folder to jboss. But I now copied files of newer version from jboss-seam (2.1.1CR2) folder into jboss/server/default/lib. It didn't make any difference deploying my project, where I still got the message Welcome Seam 2.1.0.


                Don't know, what the reason is. Perhaps I reinstall JBoss 4.2.3(?) and hope hope. it works.


                Thanks and best regards,


                Dirk


                PS: Merry XMas!