8 Replies Latest reply on Nov 30, 2005 11:33 AM by Rakoto Mireille

    ClassCastException/Entity Bean Remoting

    Bill Burke Master

      So TOmcat 5.5 is a remote client to the EJB3 server and this problem shows up in the Tomcat client only? The EJB3 server throws no errors? If so this is most probably a packaging error or a Tomcat classloader bug.

      If you are running with Tomcat embedded in a JBoss application server, please tell me the version of JBoss you are using.

        • 1. Re: ClassCastException/Entity Bean Remoting
          Harald Höppner Newbie

          I have exactly the same problem as LordKaos has. The ArrayList work but single Objects throw a ClassCastException.
          Here a code fragment and its output:

          ToolDAO toolDAO = (ToolDAO)ctx.lookup(ToolDAORemote.class.getName());
          Collection col = toolDAO.findAll();
          Object o = col.iterator().next();
          Tool tool = new Tool();
          System.out.println(o.getClass());
          System.out.println(tool.getClass());
          System.out.println(Tool.class);
          System.out.println(o.getClass() == Tool.class);
          System.out.println(tool.getClass() == Tool.class);

          Here the jboss log output:
          [STDOUT] class org.tools.Tool
          [STDOUT] class org.tools.Tool
          [STDOUT] class org.tools.Tool
          [STDOUT] false
          [STDOUT] true

          This look like a mixture in ejb3-achive and the war-archive but I doule checked that.

          I use JBoss4.0.2 with EJB3 extension in standard configuration.

          The only idea I have is to copy the Fields with reflection.

          Has somebody a better idea or a solution?

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

            I need to know is this all collocated within the same JBoss instance? Or is this a Tomcat remote client?

            • 3. Re: ClassCastException/Entity Bean Remoting
              Harald Höppner Newbie

              I found the problem.

              I created an ear file witch contained the ejb3 and the war file.
              The ejb3 archive had only the entity and session beans but not
              the backing-beans of the war achive.
              In the war achive I put a jar archive that contained both the ejb3 beans and the backing-beans (managed beans of jsf).

              And that was the problem.

              After removing the ejb3 beans from the jar achive and adding the ejb3 achive to the WEB-INF/lib the problems where gone.

              ciao,
              harry

              • 4. Re: ClassCastException/Entity Bean Remoting
                Alex Taylor Newbie

                Haho,
                Are you running this in Tomcat inside JBoss, or external?

                I am running in an external Tomcat.

                So you placed your .ejb3 file inside the WEB-INF/lib directory? Does it deploy correctly there?

                I am not sure that it will inside an external tomcat, but worth a try.

                I also had a jar file in my war that contained the entity beans - I will try placing the .ejb3 file there and see how it goes.

                Alex.

                • 5. Re: ClassCastException/Entity Bean Remoting
                  Alex Taylor Newbie

                  Bill,
                  After much research I guess my question is this:

                  Is there any known current way to correctly deploy an ejb3 entity bean inside a remote tomcat container?

                  I know this isn't strictly a JBoss/EJB3 question, but I have tried everything here. Interestingly, I get a similar ClassCastException inside Tomcat if I include my remote session beans inside a jar file in the shared libs of Tomcat.

                  It would seem that Tomcat is not correctly processing the annotations inside the entity beans, hence the ClassCastException. perhaps I am not deploying one of the jars that I should be in Tomcat?

                  Any help would be much appreciated.

                  Cheers,
                  Alex.

                  • 6. Re: ClassCastException/Entity Bean Remoting
                    Olivier Liemans Newbie

                    Hi,
                    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.

                    Merci.
                    Olivier Liemans.

                    • 7. Re: ClassCastException/Entity Bean Remoting
                      David Leeson Newbie

                      I got some results with the ClassCastException by also changing the server/default/deploy configuration files. The ear-deployer.xml has a setting called CallByValue, which if set to true removes the problem with EJB's returning concrete objects which if cast at the client end throw the CCE.

                      If you are also using JNDI to store and retrieve objects, then there is another file in server/default/conf called jboss-service.xml with another similarly set parameter (CallByValue). Apparently, if you set this to true, it will resolve the naming server issue (though I can't guarantee this as I haven't tried it).

                      Hope this helps.

                      BTW, also went through the library/jar reorg process, which initially had no real improvement except increasing my understanding of the class loader!

                      • 8. Re: ClassCastException/Entity Bean Remoting
                        Rakoto Mireille Newbie

                         

                        "LordKaos" wrote:
                        Bill,
                        After much research I guess my question is this:

                        Is there any known current way to correctly deploy an ejb3 entity bean inside a remote tomcat container?

                        I know this isn't strictly a JBoss/EJB3 question, but I have tried everything here. Interestingly, I get a similar ClassCastException inside Tomcat if I include my remote session beans inside a jar file in the shared libs of Tomcat.

                        It would seem that Tomcat is not correctly processing the annotations inside the entity beans, hence the ClassCastException. perhaps I am not deploying one of the jars that I should be in Tomcat?

                        Any help would be much appreciated.

                        Cheers,
                        Alex.


                        LordKaos,
                        That's what i want too, do you find how to do this ?

                        Best regards