5 Replies Latest reply on Jan 18, 2006 11:17 AM by Vivek Srivastav

    ClassCastException/Entity Bean Remoting

    Olivier Liemans Newbie

      I have done an ear file including a par archive and a ejb3 archive that deploys well on a jboss server (4.0.3).

      Everything works fine whith a client java application :
      I can access the session façade of my business layer (provided by the ear) from a standalone client from eclipse and invoke the fonctions through a remote interface.

      It goes wrong from a web application, whitch is:
      - packaged in a separate war file,
      - deployed in the same jboss server or a second one (same version),
      I get the following problems:

      1) on an invocation returning an ejb3 pojo :
      MyPojoEJB3 instance = remote.findById(1);
      ERROR - java.lang.ClassCastException : the.total.package.MyPojoEJB3 at $Proxy147.findById(Unknown Source)
      Note that the fonction itself is invoked and terminates perfectly.

      2) on an invocation returning a Collection of ejb3 pojos : Collection<MyPojoEJB3> instances = remote.getList();
      - the collection is well retreive but accessing to the pojos inside the collection causes the same ClassCastException described above.

      Note that the war file contains (in WEB-INF/lib) an archive business-delegate.jar that defines all the business classes needed by the war.

      If I package all in the ear (par + ejb3 + war) everything works well.
      But unfortunetly, I need to separate the war from the ear to deploy it on a secand jboss server (or tomcat).

      I know that the same problem has already been described (in june 2005 with jboss 4.0.2 extended for ejb3) on this forum but no clear answer was published.

      Any help would be much appreciated.

      Olivier Liemans.

        • 1. Re: ClassCastException/Entity Bean Remoting
          Bill Burke Master

          Can you write a very simple testcase and attach it to a JIRA bug report please under the EJB3 project? And explicit directions on how to reproduce the problem?

          WARs have a scoped classloader by default (required by spec). You can turn this off to use the unified, flat classloader scheme and this should fix the problem on JBoss.

          But, if you are invoking on a remote interface, this shouldn't be a problem.

          • 2. Re: ClassCastException/Entity Bean Remoting
            Nic Holbrook Newbie


            "bill.burke@jboss.com" wrote:

            WARs have a scoped classloader by default (required by spec). You can turn this off to use the unified, flat classloader scheme and this should fix the problem on JBoss.

            How do I turn this off? I have the exact same problem.

            • 3. Re: ClassCastException/Entity Bean Remoting
              Nic Holbrook Newbie

              For more information, if I have a par, ejb3, and war in the same ear, I can't even include the par in the WEB-INF/lib of the war or I get ClassCastExceptoins. I need to be able to give the par to other web app developers as a jar for access to our entity objects. Is anybody looking into this? Just wondering since I haven't heard or seen anything yet.

              • 4. Re: ClassCastException/Entity Bean Remoting
                Vivek Srivastav Newbie

                I am getting the same ClassCastException when using entity Bean in JBoss 4.0.3SP1. This only happens when I do a find on primary key using EntityManager's find method. It seems like the object is retrieved appropriately in the ejb-tier, however when returning to the Web-tier there is somewhere, it's throwing ClassCastException. When I am using a collection class to retrieve all the Books, I seem to be getting the appropriate values.

                I have following structure in my code:



                ejb3Test.war has the following jar file for Book class


                23:19:23,125 INFO [STDOUT] java.lang.ClassCastException: org.vss.ejb3.eb.Book
                23:19:23,125 INFO [STDOUT] at $Proxy107.getBook(Unknown Source)
                23:19:23,125 INFO [STDOUT] at org.vss.web.struts.library.SimulateDB.loadBookById(SimulateDB.java:34)
                23:19:23,125 INFO [STDOUT] at org.vss.web.struts.library.action.BookEditAction.editBook(BookEditAction.java:45)
                23:19:23,125 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                23:19:23,125 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                23:19:23,125 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                23:19:23,125 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)

                • 5. Re: ClassCastException/Entity Bean Remoting
                  Vivek Srivastav Newbie

                  I fixed it by removing ejb3Test-client.jar from the war file.