10 Replies Latest reply on Jun 30, 2009 2:45 PM by Diego Y K

    Hibernate Session from entityManager.getDelegate()

    Diego Y K Newbie

      Hi I'm trying to obtain the HibernateSession from my Entity Manager on a SFSB.




      @PersistenceContext
      protected EntityManager entityManager;
      
      public List<Connector> search() {
                      HibernateSessionProxy session = ((HibernateSessionProxy) entityManager.getDelegate());
                      (...)
              }



      I get a runtime exception.


      java.lang.RuntimeException: could not proxy delegate


      Then, first I thought that this error was due my casting, but I debuged the application and saw that the error comes from the entityManager.getDelegate();




      Caused by: java.lang.ClassCastException: org.hibernate.ejb.EntityManagerImpl cannot be cast to org.hibernate.Session


      I've searched the forum and doesn't seens to be anything wrong on my Application.


      I'm using Seam 2.1 on Glassfish.


        • 1. Re: Hibernate Session from entityManager.getDelegate()
          Jean Luc Apprentice

          Hmm... Seam 2.1.1 and JBoss 5 works fine for (org.jboss.seam.persistence.HibernateSessionProxy)em.getDelegate()


          Evaluate in the debugger entityManager.getDelegate() and see what you get, perhaps there is an extra level of indirection on Glassfish.

          • 2. Re: Hibernate Session from entityManager.getDelegate()
            Diego Y K Newbie

            I think it's a problem due the Glassfish too.


            I got the following when executing


            entityManager.getDelegate()





            WARNING: java.lang.RuntimeException: could not proxy delegate
                 at org.jboss.seam.persistence.HibernatePersistenceProvider.proxyDelegate(HibernatePersistenceProvider.java:128)
                 at org.jboss.seam.persistence.EntityManagerProxy.getDelegate(EntityManagerProxy.java:97)
                 at com.diebold.multichannel.configtool.model.connector.session.ConnectorAction.search(ConnectorAction.java:133)
                 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:22)
                 at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                 at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
                 at org.jboss.seam.Component.getInstanceFromFactory(Component.java:2043)
                 at org.jboss.seam.Component.getInstance(Component.java:1978)
                 at org.jboss.seam.Component.getInstance(Component.java:1950)
                 at org.jboss.seam.Component.getInstance(Component.java:1944)
                 at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2311)
                 at org.jboss.seam.Component.getValueToInject(Component.java:2263)
                 at org.jboss.seam.Component.injectAttributes(Component.java:1703)
                 at org.jboss.seam.Component.inject(Component.java:1521)
                 at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
                 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.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
                 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.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                 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.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:579)
                 at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:483)
                 at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:205)
                 at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4003)
                 at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
                 at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
                 at $Proxy55.typeListFactory(Unknown Source)
                 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:22)
                 at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                 at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                 at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:43)
                 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.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                 at org.javassist.tmp.java.lang.Object_$$_javassist_6.typeListFactory(Object_$$_javassist_6.java)
                 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:22)
                 at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                 at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
                 at org.jboss.seam.Component.getInstanceFromFactory(Component.java:2043)
                 at org.jboss.seam.Component.getInstance(Component.java:1978)
                 at org.jboss.seam.Component.getInstance(Component.java:1950)
                 at org.jboss.seam.Component.getInstance(Component.java:1944)
                 at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
                 at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
                 at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
                 at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
                 at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
                 at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
                 at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
                 at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                 at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                 at javax.faces.component.UISelectItems.getValue(UISelectItems.java:130)
                 at org.jboss.seam.ui.component.UISelectItems.getValue(UISelectItems.java:161)
                 at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:323)
                 at com.sun.faces.renderkit.html_basic.MenuRenderer.getOptionNumber(MenuRenderer.java:675)
                 at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:793)
                 at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:335)
                 at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
                 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:578)
                 at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                 at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                 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.servletService(ApplicationFilterChain.java:427)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:532)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                 at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.MultipartFilter.doF
            WARNING: ilter(MultipartFilter.java:90)
                 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.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                 at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                 at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                 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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                 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:246)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:313)
                 at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
                 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                 at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
                 at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
                 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
                 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
                 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
                 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
                 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
                 at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
                 at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
                 at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
                 at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
                 at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
                 at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
                 at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
                 at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
                 at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
            Caused by: java.lang.ClassCastException: org.hibernate.ejb.EntityManagerImpl cannot be cast to org.hibernate.Session
                 at org.jboss.seam.persistence.HibernatePersistenceProvider.proxyDelegate(HibernatePersistenceProvider.java:120)
                 ... 144 more
            
            
            



            • 3. Re: Hibernate Session from entityManager.getDelegate()
              Diego Y K Newbie

              I've been working on this problem.


              When I use this.


              @PersistenceContext
              protected EntityManager entityManager;



              I'm injecting my persistence context through the Container right?


              Am I not allowed to do a entityManager.getDelegate() when I inject with @PersistenceContext?


              I tried to use Seam to inject my entity manager and I managed to call entityManager.getDelegate and then cast to HibernateSession.


              But when I access the page for the first time I got the following classCastException.



              java.lang.ClassCastException: com.sun.enterprise.util.EntityManagerWrapper cannot be cast to javax.persistence.EntityManagerFactory

              But if I refresh the page by pressing F5 I can use my system without any problems.


              Actually I would rather prefer to use a Container managed PersistenceContext rather then the Seam one, but at this time if anyone could help me solve any of this problems I would be really pleased.

              • 4. Re: Hibernate Session from entityManager.getDelegate()
                Stuart Douglas Master

                Where did the EntityManagerFactory cast come into it? Are you manually trying to cast to EntityManagerFactory somewhere?

                • 5. Re: Hibernate Session from entityManager.getDelegate()
                  Diego Y K Newbie

                  I'm really not sure.


                  I think it's comming from the moment that Seam is trying to Inject the Entity Manager





                  java.lang.ClassCastException: com.sun.enterprise.util.EntityManagerWrapper cannot be cast to javax.persistence.EntityManagerFactory
                       at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:241)
                       at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:78)
                       at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107)
                       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:22)
                       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                       at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
                       at org.jboss.seam.Component.unwrap(Component.java:2237)
                       at org.jboss.seam.Component.getInstance(Component.java:2004)
                       at org.jboss.seam.Component.getInstance(Component.java:1950)
                       at org.jboss.seam.Component.getInstance(Component.java:1944)
                       at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2311)
                       at org.jboss.seam.Component.getValueToInject(Component.java:2263)
                       at org.jboss.seam.Component.injectAttributes(Component.java:1703)
                       at org.jboss.seam.Component.inject(Component.java:1521)
                       at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
                       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.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
                       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.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                       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.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:579)
                       at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:483)
                       at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:205)
                       at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4003)
                       at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
                       at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
                       at $Proxy167.typeListFactory(Unknown Source)
                       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:22)
                       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                       at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:43)
                       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.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                       at org.javassist.tmp.java.lang.Object$$javassist3.typeListFactory(Object$$javassist3.java)
                       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:22)
                       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                       at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
                       at org.jboss.seam.Component.getInstanceFromFactory(Component.java:2043)
                       at org.jboss.seam.Component.getInstance(Component.java:1978)
                       at org.jboss.seam.Component.getInstance(Component.java:1950)
                       at org.jboss.seam.Component.getInstance(Component.java:1944)
                       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
                       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
                       at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
                       at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
                       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
                       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
                       at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
                       at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                       at javax.faces.component.UISelectItems.getValue(UISelectItems.java:130)
                       at org.jboss.seam.ui.component.UISelectItems.getValue(UISelectItems.java:161)
                       at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:323)
                       at com.sun.faces.renderkit.htmlbasic.MenuRenderer.getOptionNumber(MenuRenderer.java:675)
                       at com.sun.faces.renderkit.html
                  basic.MenuRenderer.renderSelect(MenuRenderer.java:793)
                       at com.sun.faces.renderkit.htmlbasic.MenuRenderer.encodeEnd(MenuRenderer.java:335)
                       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
                       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
                       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:578)
                       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                       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.servletService(ApplicationFilterChain.java:427)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:532)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                       at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                       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.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                       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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                       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:246)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:313)
                       at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                       at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
                       at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
                       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
                       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
                       at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
                       at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
                       at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
                       at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
                       at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
                       at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
                       at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
                       at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
                       at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
                  javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: java.lang.ClassCastException: com.sun.enterprise.util.EntityManagerWrapper cannot be cast to javax.persistence.EntityManagerFactory
                       at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:3753)
                       at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3601)
                       at com.sun.ejb.containers.StatefulSessionContainer.postInvokeTx(StatefulSessionContainer.java:2714)
                       at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1379)
                       at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
                       at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:205)
                       at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
                       at $Proxy167.typeListFactory(Unknown Source)
                       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:22)
                       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                       at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:43)
                       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.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                       at org.javassist.tmp.java.lang.Object
                  $$javassist3.typeListFactory(Object$$javassist3.java)
                       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:22)
                       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                       at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
                       at org.jboss.seam.Component.getInstanceFromFactory(Component.java:2043)
                       at org.jboss.seam.Component.getInstance(Component.java:1978)
                       at org.jboss.seam.Component.getInstance(Component.java:1950)
                       at org.jboss.seam.Component.getInstance(Component.java:1944)
                       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
                       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
                       at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
                       at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
                       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
                       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
                       at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
                       at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                       at javax.faces.component.UISelectItems.getValue(UISelectItems.java:130)
                       at org.jboss.seam.ui.component.UISelectItems.getValue(UISelectItems.java:161)
                       at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:323)
                       at com.sun.faces.renderkit.html
                  basic.MenuRenderer.getOptionNumber(MenuRenderer.java:675)
                       at com.sun.faces.renderkit.htmlbasic.MenuRenderer.renderSelect(MenuRenderer.java:793)
                       at com.sun.faces.renderkit.html
                  basic.MenuRenderer.encodeEnd(MenuRenderer.java:335)
                       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
                       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
                       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:578)
                       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                       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.servletService(ApplicationFilterChain.java:427)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:532)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                       at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                       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.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                       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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                       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:246)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:313)
                       at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                       at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
                       at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
                       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
                       at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
                       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
                       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
                       at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
                       at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
                       at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
                       at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
                       at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
                       at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
                       at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
                       at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
                       at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

                  • 6. Re: Hibernate Session from entityManager.getDelegate()
                    Stuart Douglas Master

                    Can I see your persistence.xml and your components.xml?


                    In persistence.xml there are two properties:


                    <property name="jboss.entity.manager.factory.jndi.name" value="mainEntityManagerFactory"/>
                    <property name="jboss.entity.manager.jndi.name" value="entityManager" />
                    



                    Are you sure you have not used the entity manager jndi name in your components.xml instead of the entity manager factory jndi name?

                    • 7. Re: Hibernate Session from entityManager.getDelegate()
                      Diego Y K Newbie

                      Actually, I think I'm using the names defined on my components.xml.


                      Here is my persistence.xml I dont have those 2 properties, aren't those Jboss only? I'm deployin my application on glassfish.


                      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
                           <persistence-unit name="pool" transaction-type="JTA">
                      <provider>org.hibernate.ejb.HibernatePersistence</provider>
                                <jta-data-source>jdbc/pool</jta-data-source>
                               <properties>
                                   <property name="hibernate.show_sql" value="true" />
                                   <property name="hibernate.format_sql" value="true" />
                                   <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
                                   <property name="hibernate.connection.isolation" value="4096"/>
                                   <property name="hibernate.query.startup_check" value="false" />
                                   <property name="hibernate.default_batch_fetch_size" value="30" />
                                    <property name="hibernate.transaction.manager_lookup_class" 
                                            value="org.hibernate.transaction.SunONETransactionManagerLookup" />
                                     <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" />
                                        <property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehCache.xml" />              
                                     <property name="hibernate.cache.use_query_cache" value="true" />
                                     <property name="hibernate.cache.use_minimal_puts" value="false" />
                                     <property name="hibernate.cache.use_second_level_cache" value="true" />
                                </properties>     
                           </persistence-unit>
                      </persistence>



                      This is my components.xml


                      <core:init jndi-pattern="java:comp/env/ConfigTool/#{ejbName}/local"
                                debug="true" />
                      
                           <transaction:ejb-transaction />  
                      
                             <persistence:managed-persistence-context name="entityManager" 
                                auto-create="true" persistence-unit-jndi-name="java:comp/env/poolEmf"/>




                      • 8. Re: Hibernate Session from entityManager.getDelegate()
                        Stuart Douglas Master

                        You are right about that being jboss only, I did not read the full post. The root cause of the class cast error is that seam is expecting to get a EntityManagerFactory from jndi but is instead getting a EntityManager, but I am not sure how the jndi bindings are set up on glassfish so I can't really tell you any more that that.

                        • 9. Re: Hibernate Session from entityManager.getDelegate()
                          Diego Y K Newbie

                          I see, but why when I refresh my page the EntityManager is injected without any problems.


                          I was making some tests on my application and it seens to have some relation with the manner I manage my conversations.

                          • 10. Re: Hibernate Session from entityManager.getDelegate()
                            Diego Y K Newbie

                            If you are having this same problem I found the solution on this post of the seam comunity forum.


                            http://seamframework.org/Community/BugInSeamgenSeam212CR2ForGlassFishEARProjects


                            It was needed aditional configuration on components.xml


                            Everything seens to work fine so far.