3 Replies Latest reply on Mar 5, 2009 11:38 AM by mikecyl

    Entity Bean: $Proxy<nn> cannot be cast to ...

    speedo2k

      I try to learn Elcipse and JEE technology from book: Elcipse Web Tools Platform.
      While I study chapter 9 I get the following error:

      20:45:01,671 ERROR [STDERR] java.lang.ClassCastException: $Proxy126 cannot be cast to com.leagueplanet.cmp.GameLocalHome
      20:45:01,671 ERROR [STDERR] at com.leagueplanet.cmp.GameUtil.getLocalHome(GameUtil.java:63)
      20:45:01,671 ERROR [STDERR] at com.leagueplanet.servlet.GameServlet.doPost(GameServlet.java:67)

      When I look at JINDI I see that:

      GameLocal (proxy: $Proxy126 implements interface com.leagueplanet.cmp.GameLocalHome)

      Line which case error is (File: GameUtil):
      /** Cached local home (EJBLocalHome). Uses lazy loading to obtain its value (loaded by getLocalHome() methods). */
      private static com.leagueplanet.cmp.GameLocalHome cachedLocalHome = null;

      public static com.leagueplanet.cmp.GameLocalHome getLocalHome() throws javax.naming.NamingException
      {
      if (cachedLocalHome == null) {
      cachedLocalHome = (com.leagueplanet.cmp.GameLocalHome) lookupHome(null, com.leagueplanet.cmp.GameLocalHome.JNDI_NAME, com.leagueplanet.cmp.GameLocalHome.class);
      }
      return cachedLocalHome;
      }
      (File: GameLocalHome)
      public static final String JNDI_NAME="GameLocal";

        • 1. Re: Entity Bean: $Proxy<nn> cannot be cast to ...
          peterj

          Sounds like you are including the interface definition in your WAR file, remove it.

          The problem is that if both your EJB JAR file and the WAR file contain the interface definition, each has its own classloader. Then the interface in the EJB JAR will be used to create the $Proxy126, but then in the WAR file the cast will be attempted with the interface in the WAT file, which is in the other classloader, and thus not the same.

          I'm not sure what steps you would have to take in Eclipse to get it to not package the interface in the WAR file (I do all my packaging using Ant or Maven).

          • 2. Re: Entity Bean: $Proxy<nn> cannot be cast to ...
            speedo2k

            Great, it works. But I try to understand what was wrong.

            Previously I had in Dynamic Web Application i ndependencies:
            - use EJB client jar and have checkbox on ejb client jar
            Now I have
            - Allow both and checkbox on ejb jar

            Now works, when all is on one machine JBoss and Client on the same JVM.

            Does this configuration will work also on distributed configuration?

            • 3. Re: Entity Bean: $Proxy<nn> cannot be cast to ...
              mikecyl

               

              "speedo2k" wrote:
              Great, it works. But I try to understand what was wrong.

              Previously I had in Dynamic Web Application i ndependencies:
              - use EJB client jar and have checkbox on ejb client jar
              Now I have
              - Allow both and checkbox on ejb jar

              Now works, when all is on one machine JBoss and Client on the same JVM.

              Does this configuration will work also on distributed configuration?


              hi, speedo2k, I have the same problem as you. Could you please tell me how you reached to make it work in Eclipse? Thanks a lot!