7 Replies Latest reply on Apr 12, 2010 10:42 AM by rdelarosa

    ClassCastException

    rdelarosa

      Hi,

       

      I am trying to obtain a fererence to a "ProcessEngine" with the following code:

       

      org.jbpm.api.ProcessEngine processEngine = null ;


      Configuration configuration = new Configuration();
                 
             // build a process engine from a configuration
             try {
                processEngine = configuration.buildProcessEngine();  /* ManejadorJBPM4.java:360 */
             }
             catch(java.lang.Exception exc) {
                exc.printStackTrace();
             }

       

      But the following error is printed on the console:

       

      17:47:29,171 ERROR [STDERR] java.lang.ClassCastException: org.jbpm.pvm.internal.
      processengine.ProcessEngineImpl cannot be cast to org.jbpm.pvm.internal.processe
      ngine.ProcessEngineImpl
      17:47:29,171 ERROR [STDERR]     at org.jbpm.pvm.internal.cfg.ConfigurationImpl.b
      uildProcessEngine(ConfigurationImpl.java:81)
      17:47:29,171 ERROR [STDERR]     at org.jbpm.api.Configuration.buildProcessEngine
      (Configuration.java:105)
      17:47:29,171 ERROR [STDERR]     at co.com.gestiontek.supercade.util.ManejadorJBP
      M4.iniciarProceso(ManejadorJBPM4.java:360)
      17:47:29,171 ERROR [STDERR]     at co.com.gestiontek.supercade.action.workflow.R
      egistroTramite.iniciarTramiteEnrolamiento(RegistroTramite.java:354)
      17:47:29,171 ERROR [STDERR]     at co.com.gestiontek.supercade.action.workflow.R
      egistroTramite.iniciarTramite(RegistroTramite.java:292)
      17:47:29,171 ERROR [STDERR]     at co.com.gestiontek.supercade.action.workflow.R
      egistroTramite.registrarTramite(RegistroTramite.java:228)

      ....

       

      I don't understand why there is a "ClassCastException" due to a casting from

      org.jbpm.pvm.internal.processengine.ProcessEngineImpl to the same class ??

       

      Any help is very appreciated.

       

      Ricardo De la Rosa

        • 1. Re: ClassCastException
          rebody

          Hi ricardo,

           

            I think you should make sure if there is more than one ClassLoader could load the ProcessEngineImpl class. It looks like the ProcessEngineImpl being loaded twice so it can't be cast from a ClassLoader to another one.

           

          cheers.

          1 of 1 people found this helpful
          • 2. Re: ClassCastException

            Hi ricardo,

             

            Huisheng Xu is right, check for classloading. Can you provide more information about how do you load ProcessEngine or scenario in which error occurs?

            1 of 1 people found this helpful
            • 3. Re: ClassCastException
              rdelarosa

              Hi Nenad ,

               

              Where can I find more information about how do I load ProcessEngine ?

              ___

              I changed the code to the following equivalent code:

               

              Configuration configuration = new Configuration();
              configuration = configuration.setResource("jbpm.cfg.xml");

              processEngine = configuration.buildProcessEngine();

              ___

              The exception thrown is:

              java.lang.ClassCastException: org.jbpm.pvm.internal.processengine.ProcessEngineImpl cannot be cast to

                  at org.jbpm.pvm.internal.cfg.ConfigurationImpl.buildProcessEngine(ConfigurationImpl.java:81)
                  at co.com.gestiontek.supercade.util.ManejadorJBPM4.<init>(ManejadorJBPM4.java:52)
                  at co.com.gestiontek.supercade.action.workflow.RegistroTramite.init(RegistroTramite.java:100)
                  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:32)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                   at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)

              _____________________________________

               

              The content of the file named "jbpm.cfg.xml" is the following:

               

              <?xml version="1.0" encoding="UTF-8"?>

               

              <jbpm-configuration jndi-name="java:/ProcessEngine">

               

                <import resource="jbpm.default.cfg.xml" />
                <import resource="jbpm.tx.hibernate.cfg.xml" />
                <import resource="jbpm.jpdl.cfg.xml" />

              </jbpm-configuration>

              _______

              Thank you in advance,

              Ricardo

              • 4. Re: ClassCastException
                rdelarosa

                Hi Huisheng Xu ,
                Where can I find more information about how do I load ProcessEngine ?
                ___
                I changed the code to the following equivalent code:

                 

                Configuration configuration = new Configuration();
                configuration = configuration.setResource("jbpm.cfg.xml");

                 

                processEngine = configuration.buildProcessEngine();
                ___

                 

                The exception thrown is:

                 

                java.lang.ClassCastException: org.jbpm.pvm.internal.processengine.ProcessEngineImpl cannot be cast to

                 

                    at org.jbpm.pvm.internal.cfg.ConfigurationImpl.buildProcessEngine(ConfigurationImpl.java:81)
                    at co.com.gestiontek.supercade.util.ManejadorJBPM4.<init>(ManejadorJBPM4.java:52)
                    at co.com.gestiontek.supercade.action.workflow.RegistroTramite.init(RegistroTramite.java:100)
                    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:32)
                     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                     at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)

                 

                _____________________________________

                 


                The content of the file named "jbpm.cfg.xml" is the following:

                 


                <?xml version="1.0" encoding="UTF-8"?>

                 


                <jbpm-configuration jndi-name="java:/ProcessEngine">

                 


                  <import resource="jbpm.default.cfg.xml" />
                  <import resource="jbpm.tx.hibernate.cfg.xml" />
                  <import resource="jbpm.jpdl.cfg.xml" />

                 

                </jbpm-configuration>

                 

                _______

                 

                Thank you in advance,

                 

                Ricardo

                • 5. Re: ClassCastException
                  swiderski.maciej

                  Hi,

                   

                  just make sure that you don't have multiple jbpm installation on your server. For instance, if you installed jbpm in JBoss following user guide and you developed your own application that embed jbpm this can probably cause ClassCastException.

                  In that scenario you don't need to create process engine any more. You could look it up from JNDI.

                  Another way is to have only jbpm embedded in your application and not deploy it as separate service.

                   

                  HTH

                  Maciej

                  • 6. Re: ClassCastException

                    Hi ricardo,

                     

                    Like maciej pointed out, check for multiple instances of jbpm if you are deploying it on AS. Also to add to his post, if you use Jboss and use jbpm as service in your application, check how you bind and unbind ProcessEngine to JNDI (I'm not sure whether the supplied service jbpm-jboss5.jar is properly written). This can cause classcast exceptions on application hot deploy.

                    • 7. Re: ClassCastException
                      rdelarosa

                      Macied and Nenad: thank you for your responses, they help me to solve the problem.

                      Effectively, the error is that jbpm.jar is present twice in the deployment environment. The first occurrence is in the directory "jboss-5.0.0.GA\server\default\deploy\jbpm\jbpm-service.sar". The second occurrence is inside the .ear file of my application.

                       

                      To solve the problem, I deleted the second occurrence from the .ear file.

                      Besides, I added the class containing "configuration.buildEngine()" to the first occurrence of jbpm.jar.

                       

                      Thank you for helping me,

                      Ricardo.