4 Replies Latest reply on Mar 31, 2010 3:09 PM by Sridevi KA

    ClassCast Problem

    Claus Andersen Newbie

      Hello,

      I am encountering a strange problem. I wrote a very simple Processdefinition:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <process-definition
       xmlns="" name="objectTest">
       <start-state name="start">
       <event type="node-leave">
       <action name="action1" class="com.test.SetUpActionHandler"/>
       </event>
       <transition name="" to="node1"></transition>
       </start-state>
       <end-state name="end">
       </end-state>
       <node name="node1">
       <action class="com.test.ObjectTestActionHandler" />
       <transition name="" to="end"></transition>
       </node>
      </process-definition>
      


      In the SepUpActionHandler class I declare a simple TestObject and put it into the ContextInstance:

      package com.test;
      
      import org.jbpm.graph.def.ActionHandler;
      import org.jbpm.graph.exe.ExecutionContext;
      
      public class SetUpActionHandler implements ActionHandler {
      
       private static final long serialVersionUID = 1L;
      
       public void execute(ExecutionContext executionContext) throws Exception
       {
       TestObject to = new TestObject();
       to.setText("TestString");
       executionContext.getContextInstance().setVariable("Test", to);
       }
      }
      


      The TestObject itself is a very minimal serializable object:

      package com.test;
      
      import java.io.Serializable;
      
      public class TestObject implements Serializable {
      
       private static final long serialVersionUID = 1L;
      
       private String _text = "leer";
      
       public TestObject()
       {
      
       }
      
       public String getText()
       {
       return _text;
       }
      
       public void setText(String s)
       {
       _text = s;
       }
      }
      


      And finally, in the ObjectTestActionHandler, I retrieve the TestObject from the ContextInstance:

      package com.test;
      
      import org.jbpm.graph.def.ActionHandler;
      import org.jbpm.graph.exe.ExecutionContext;
      
      public class ObjectTestActionHandler implements ActionHandler {
      
       private static final long serialVersionUID = 1L;
      
       public void execute(ExecutionContext executionContext) throws Exception
       {
       Object o = executionContext.getContextInstance().getVariable("Test");
       TestObject to = (TestObject) o;
      
       executionContext.getToken().signal();
       }
      }
      


      When I execute this process in Eclipse, everything runs fine, there are no errors. But when I deploy it to a JBoss AS (4.0.4) and start it using the jbpm-web-console, I get a ClassCastException with the message: "com.test.TestObject cannot be cast to com.test.TestObject"

      The Exception is thrown by the ObjectTestActionHandler in the line where the casting is done:

      TestObject to = (TestObject) o;
      


      Does anybody know why this happens?

      Regards,

      Claus Andersen

        • 1. Re: ClassCast Problem
          Arutha Belron Newbie


          Hey,

          I had the same problem last week, I'd like to call "Cannot cast smtptoesb.server.smtpmail to smtptoesb.server.smtpmail". The cause of this was rather simple, but I still took many hours not relaxing in front of the TV to figure it out.

          The problem for me was that Jboss worked with an older version of the class than the application itself, trying to cast will throw this problem. Try shutting down Jboss, removing all tmp related to this work, cleaning the build folder, redeploying it and running it again.

          I realise it's not ideal, rebooting Jboss, I tried doing this @runtime, but Jboss locks the tmp-files that need to be deleted, and for some reason, even after redeploying in this situation, Jboss kept using the old Pojo class.

          With 'older' version, I mean that even though the class may be exactly the same, it was compiled at an earlier time.

          • 2. Re: ClassCast Problem
            Martin Weiler Apprentice

            IMO the question is how you are deploying your process and its related java classes? If you deploy it through Eclipse for example make sure you include the java classes as well. They will end up in the database and jBPM can pull them from there at runtime.

            Are you packaging them somewhere else inside the app server?

            • 3. Re: ClassCast Problem
              Arutha Belron Newbie


              A followup, I just remembered you can indicate compatibility with Serializable class-versions using static final long serialVersionUID. Would be a prettier solution than the ramble I held up there.

              • 4. Re: ClassCast Problem
                Sridevi KA Newbie

                Hi..

                 

                I am also facing the same problem.Did u find any solution for this other than restarting the server.Please help me on this.

                Thanks in advance