0 Replies Latest reply on Jul 15, 2014 9:37 AM by gizzie

    java.lang.Class cannot be cast to java.lang.String when invoking a EJB Bean Method

    gizzie

      I've faced with the problem. I've successfully lookuped my remote bean from JBoss, but when I try to invoke any of its method next exception is about to appear:

       

          java.lang.Class cannot be cast to java.lang.String.

       

      Full stack trace is:

       

        java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String

        at org.jboss.ejb.client.remoting.ProtocolMessageHandler.readAttachments(ProtocolMessageHandler.java:56)

        at org.jboss.ejb.client.remoting.InvocationExceptionResponseHandler$MethodInvocationExceptionResultProducer.getResult(InvocationExceptionResponseHandler.java:85)

        at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:212)

        at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:47)

        at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:214)

        at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:96)

        at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:203)

        at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:341)

        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:126)

        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:107)

        at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:90)

        at com.sun.proxy.$Proxy32.createEvent(Unknown Source)

        at com.mypackage.FacadeImpl.createEvent(FacadeImpl.java:89)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)

        at com.sun.proxy.$Proxy28.createEvent(Unknown Source)

       

      Last row is the invocation of my method called "CreateEvent".

      I guess the exception is throwned inside "getResult()" method of EJBClientInvocationContext.

       

      My code is:

         

      IEventDao eventDao = (IEventDao) ctx.lookup("java:/task/EventDao!MyPackage.IEventDao");

       

      EventDao has been successfully gotten from the remote.

      Trying to invoke a method:

         

      public Event createEvent(final Event event) {

             return eventDao.createEvent(event);

      }


      Event event = new EventImpl("Test event: Star Wars: Episode VI");

      createEvent(event); <-- Line #89. Exception has been throwned.

       

      CreateEvent method body. But just for your info: it's not even enter this piece of code. It throwns the exception before even invoking `entityManager.persist(event);`

       

          @Transactional(propagation = Propagation.REQUIRED)

          public Event createEvent(Event event) {

              entityManager.persist(event);

              return event;

          }

       

      Any ideas? Thank you.