1 Reply Latest reply on Jan 17, 2007 4:54 AM by Pete Muir

    Statefull EJB extends from EntityHome throws ClassCastExcept

    leon lee Newbie

      I use stateful ejb extends the EntityHome, but I want to use @PersistenceContext inject the EntityManager, so i can use ejb container transaction management, but it throws Exception. I don't know why, who can help me? Does EntityHome must use itself EntityManager? Thanks your reply.
      My ejb:

      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.RequestParameter;
      import org.jboss.seam.framework.EntityHome;
      
      import com.foo.psims.entity.MyEntity;
      
      @Stateful
      @Name("myEntityHome")
      public class MyEntityHome extends EntityHome<MyEntity> implements
       BaseHomeInter<MyEntity> {
      
       private static final long serialVersionUID = -7234024691621156847L;
      
       @PersistenceContext
       EntityManager em;
      
       @RequestParameter
       Long myEntityId;
      
       @Override
       public Object getId() {
       if (myEntityId == null) {
       return super.getId();
       } else {
       return myEntityId;
       }
       }
      
       @Override
       @Begin
       public void create() {
       super.create();
       }
      
       @Remove
       @Destroy
       public void destroy() {
      
       }
      
       public String delete() {
       return super.remove();
       }
      
       @Override
       public EntityManager getEntityManager() {
       return em;
       }
      
       @Override
       public void setEntityManager(EntityManager entityManager) {
       em = entityManager;
       }
      
      }
      

      Exception:

      Exception during INVOKE_APPLICATION(5): java.lang.ClassCastException: org.hibernate.ejb.EntityManagerImpl
      org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
      org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
      org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:203)
      org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
      $Proxy377.persist(Unknown Source)
      com.foo.psims.action.BaseHomeInter$$FastClassByCGLIB$$c393af8b.invoke(<generated>)
      net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
      org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
      org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:73)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
      org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:39)
      sun.reflect.GeneratedMethodAccessor589.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:585)
      org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
      org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
      org.jboss.seam.interceptors.ExceptionInterceptor.handleExceptions(ExceptionInterceptor.java:38)
      sun.reflect.GeneratedMethodAccessor588.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:585)
      org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
      org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
      org.jboss.seam.intercept.RootInterceptor.createSeamInvocationContext(RootInterceptor.java:144)
      org.jboss.seam.intercept.RootInterceptor.invokeInContexts(RootInterceptor.java:129)
      org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:102)
      org.jboss.seam.intercept.ClientSideInterceptor.interceptInvocation(ClientSideInterceptor.java:82)
      org.jboss.seam.intercept.ClientSideInterceptor.intercept(ClientSideInterceptor.java:51)
      com.foo.psims.action.BaseHomeInter$$EnhancerByCGLIB$$fea389ff.persist(<generated>)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:585)
      com.sun.el.parser.AstValue.invoke(AstValue.java:151)
      com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
      com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
      com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
      org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
      javax.faces.component.UICommand.broadcast(UICommand.java:106)
      javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)
      javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)
      org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
      org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:32)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:46)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      java.lang.Thread.run(Thread.java:595)