7 Replies Latest reply on Jan 2, 2007 11:33 AM by alexg79

    ClassCastException when casting to remote interface

    lowy

      Hi,

      I use JBoss 4.0.5 GA with EJB 3 with Eclipse.
      I have an EJB- project and a Web-project. They are (for now) running in the same VM in JBoss.

      When I get my SessionBean - stub in my web app (via Naming service) and try to cast it to the remote interface, I get a ClassCastException.
      I already found out that the problem lies in the fact that 2 remote interface class files are deployed. It's described in the wiki
      http://wiki.jboss.org/wiki/Wiki.jsp?page=CommonHurdlesAndDifficultiesYouMayEncounterDuringEJB3Development

      The wiki presents 3 solutions:
      1. remove the duplicate interface from one of the deployed libs.
      I found out that this works in principle.
      My problem with this is, that I don't use an Ant build file where I could simply exclude the file. I use Eclipse to generate the EAR / WAR archive (with Export to... ). Removing the remote interface from the web-archive afterwards solves the problem with the ClassCastException, but is much too time-consuming .

      2. run your application in different VMs -> not a good solution for me right now

      3. enable CallByValue for JNDI
      unfortunately this is not elaborated in the Wiki. From other resources, I found out that some changes to config files should be made, but the descriptions did not fit to JBoss 4.0.5 (obviously the conf-files have been reorganized). I tried to implement the changes all the same but it did not work!
      Next I remembered that during the Jboss install there was an option to "Enable deployment isolation" which sounded like it could solve the problem. So I reinstalled JBoss with this option activated. Unfortunately this did not solve the problem neither.

      One more strang fact: the ClassCastException only occurs if the EJB is a stateful SessionBean. With a stateless SessionBean I have no problem.

      I have already spent way too much time with this problem, so I would be very grateful if s.o. could help me with this.







        • 1. Re: ClassCastException when casting to remote interface
          jahlborn

          in 4.0.5.GA the naming value to change is now in:

          deploy/naming.sar/META-INF/jboss-service.xml

          • 2. Re: ClassCastException when casting to remote interface
            lowy

            I have set CallByValue to true in deploy/naming.sar/META-INF/jboss-service.xml.
            The ClassCastException is still there.
            Is there anything else I have to do?

            • 3. Re: ClassCastException when casting to remote interface
              santosh291

              Hello, I ran into a similar problem few days ago, and the issue was with packaging the ear, there were some class files copied incorrectly.

              How are you packaging your ear? can you list the contents?

              • 4. Re: ClassCastException when casting to remote interface
                lowy

                Hi,
                as I wrote in my original post, I use Eclipse to generate the EAR archive (for the EJB project) and WAR archive (for the web project). I'm not sure but I think this is a function provided by the Exadel Studio plugin that I use.

                The only thing to do in Eclipse is to add a reference of the EJB project to the web project. With this, a jar file containing the EJB-project's class files will be automatically included in the WAR file, in
                WEB-INF\lib
                I don't see any possibility to influence this behavior.

                • 5. Re: ClassCastException when casting to remote interface
                  alexg79

                   

                  as I wrote in my original post, I use Eclipse to generate the EAR archive (for the EJB project) and WAR archive (for the web project). I'm not sure but I think this is a function provided by the Exadel Studio plugin that I use.

                  You should package only the remote interface files in your Web project. I have a similar thing going on, and I have an extra project for the remote interface files.
                  It is quite likely that the problem stems from having two copies of the same code deployed.
                  Besides, I packaged the WAR inside the EAR, and not separately.

                  • 6. Re: ClassCastException when casting to remote interface

                    Salam,
                    With ECLIPSE, when you create the war file, don't include the interfaces classes by specifying this on the packaging configuration.
                    you can see the JBoss Tutorial for creating EJB.

                    • 7. Re: ClassCastException when casting to remote interface
                      alexg79

                       

                      With ECLIPSE, when you create the war file, don't include the interfaces classes by specifying this on the packaging configuration.
                      you can see the JBoss Tutorial for creating EJB.

                      I must remind that the "packaging configuration" is a JBossIDE specific feature. Normally, you create an EAR project and add your Web and EJB projects in it. That approach works with all application servers.