4 Replies Latest reply on Feb 20, 2004 8:22 PM by aradka

    ClassCastException - revisited

    aradka

      I've seen allot of posts on this general topic, but it seems what I am doing is so basic, I'm hoping it's just a 'moment' and I'm just not packaging everything correctly.

      I am trying to connect to an ejb deployed in another ear. I have ALWAYS gotten ClassCastExceptions but I've always been able to just put my ejb's and wars in the same ear, and it would work. Now I really need to seperate everything.

      I'm using jboss-3.2.3, hibernate-2.1, and xdoclet-1.2. No errors at deployment time of either ear.

      My ejb's are deployed in hibernate-repository.ear
      META-INF/
      META-INF/MANIFEST.MF
      mv.jar <----- hibernate POJO's
      hibernate-repository.sar <----- hibernate mapping files
      hibernate-service.jar <----- wrapper session bean
      .
      .other hibernate libraries.
      .
      META-INF/jboss-app.xml
      META-INF/application.xml

      Session bean interfaces and util are created with Xdoclet.
      application.xml is pretty standard
      jboss-app.xml
      <jboss-app>
      <loader-repository>hibernate:loader=hibernate.ear</loader-repository>


      hibernate-repository.sar

      </jboss-app>

      My client is in mv-test.ear
      META-INF/
      META-INF/MANIFEST.MF
      mv.jar <----same as in hibernate-service.ear
      hibernate-interface.jar <----interface and util classes created by xdoclet
      mv-test.war <----webworks client
      META-INF/application.xml
      META-INF/jboss-app.xml
      jboss-app.xml
      <jboss-app>
      <loader-repository>mv-test:loader=mv-test.war</loader-repository>
      </jboss-app>

      Here's where I try to access a session bean in my action class
      try {
      // obtain sesison bean
      IHibernateService hs = HibernateServiceUtil.getHome().create();

      org = ( Orginization ) hs.load( Orginization.class, new Long(1) );
      }
      catch( Exception ex )
      {
      _log.error( "exception: ", ex );
      }
      }

      Here's the code that throws the ClassCastException (created by xdoclet)
      HibernateServiceUtil.java
      public static com.rubicon.repository.hibernate.IHibernateServiceHome getHome() throws javax.naming.NamingException
      {
      if (cachedRemoteHome == null) {
      cachedRemoteHome = (com.rubicon.repository.hibernate.IHibernateServiceHome) lookupHome(null, com.rubicon.repository.hibernate.IHibernateServiceHome.JNDI_NAME, com.rubicon.repository.hibernate.IHibernateServiceHome.class);
      }
      return cachedRemoteHome;
      }

      Let's see what else....
      xdoclet from HibernateServiceEJB.java
      /**
      * @created December 12, 2002
      * @ejb.bean name="HibernateService" type="Stateless" view-type="remote"
      * description="hibernate service"
      * jndi-name="ejb/HibernateService"
      * @ejb.util generate="physical"
      * @ejb.permission unchecked="true"
      * @ejb.transaction type="Required"
      */

      O.K. that's all I can thin k of that would be relevant. What am I doing wrong???!!!

      Thanks,
      Alex

        • 1. Re: ClassCastException - revisited
          aradka

          Oh yeah, I guess the actual exception would be helpful

          java.lang.ClassCastException
          at com.rubicon.repository.hibernate.HibernateServiceUtil.getHome(HibernateServiceUtil.java:43)
          at com.rubicon.mvh.TestAction.retrieveOrg(TestAction.java:41)
          at com.rubicon.mvh.TestAction.execute(TestAction.java:31)
          at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:173)
          at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:37)
          at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:170)
          at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:37)
          at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:170)
          at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:37)
          at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:170)
          at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:37)
          at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:170)
          at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
          at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:182)
          at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:162)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
          at com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:62)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
          at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
          at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
          at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
          at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
          at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
          at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
          at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:197)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
          at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
          at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
          at java.lang.Thread.run(Thread.java:536)

          Alex

          • 2. Re: ClassCastException - revisited
            thomas.diesler

            JBoss uses a unified class loader (UCL) for every top level deployment. I assume you package the inteface class that causes the CCE in both ears. So there are two deployments of the same interface class. Try packaging all classes that comprise the contract between you ears (value objects, interfaces, etc.) in a seperate jar.

            • 3. Re: ClassCastException - revisited
              aradka

              Yeah, I though of that. That is why I define distinct loader-repository in the respective jboss-app.xml files. I need to deploy the persistance stuff for different datasources, but they use the same classes, so I try to avoid the UCL. I don't really have that constraint on the client, so maybe I can play with that.....I don't think that it is, though. Still, I'll give it a try.

              Thanks,
              Alex

              • 4. Re: ClassCastException - revisited
                aradka

                I stand corrected, it didn't seem to care too much about the hibernate POJO's being in two places, but it really wanted the session bean interfaces to be only defined once. So I guess the question now is why did the classloader not act as I expected.
                Having the exact same class file in two different ears, with independent classloaders defined, didn't work. Why? Did I not define the classloaders correctly in jboss-app.xml?

                Alex