10 Replies Latest reply on Feb 14, 2005 1:54 PM by keyurva

    Clustered Stateful Beans throw ClassCastException

    keyurva

      Consider this simple example:

      @Remote
      public interface Test { String getTest(); }
      
      @Stateful
      @Clustered
      public class TestBean implements Test {
       String test = "Hello";
      
       public String getTest() {
       System.out.println("getTest(): " + test);
       return test;
       }
      }
      
      public class TestClient {
       Test test = (Test)new InitialContext().lookup(Test.class.getName());
       test.getTest(); //throws ClassCastException for Clustered Bean
      }
      

      This simple TestClient works ok when the TestBean is not clustered (i.e. without the @Clustered annotation)...

      However, when it is clustered, the test.getTest() statement throws a ClassCastException (stack trace below)... (BTW, the println() in the getTest() on the server prints as expected.)

      How do I make my stateful bean work in a clustered environment?

      Thanks,
      Keyur

      Stack Trace:
      Exception in thread "main" java.lang.ClassCastException: test.TestBean
       at $Proxy1.getTest(Unknown Source)
       at test.TestClient.main(TestClient.java:14)