1 Reply Latest reply on Sep 25, 2006 7:25 PM by holmes.j

    ClassCastException on Stateless Remote Bean

    holmes.j

      Howdy,
      Just started with the new EJB 3 stuff, so I'm guessing I've done something wrong. I just can't see what it is.

      I'm getting ClassCastExceptions when trying to get the a Remote Session Bean in a JNDI lookup. It's failing on the cast to the GeoFeatureManager.

      try {
       String geoFeatureManagerName = "motionbased/GeoFeatureManagerBean/remote";
      
       InitialContext ctx = new InitialContext();
       Object object = ctx.lookup(geoFeatureManagerName);
       GeoFeatureManager geoFeatureManager = (GeoFeatureManagerBean) object;
      
       this.geoFeature = geoFeatureManager.findGeoFeature(getGeoFeaturePk());
       } catch (NamingException e1) {
       e1.printStackTrace();
       throw new SQLException(e1.getMessage());
       }


      The Remote Interface
      @Remote
      public interface GeoFeatureManager extends Serializable {
      ...
      }
      


      The Implementation of it ...

      @Stateless(name = "GeoFeatureManagerBean")
      @Remote( { GeoFeatureManager.class })
      @RemoteBinding(jndiBinding = "motionbased/GeoFeatureManagerBean/remote")
      public class GeoFeatureManagerBean implements GeoFeatureManager {
       private static final long serialVersionUID = 6211376611083502502L;
      


      I read this http://wiki.jboss.org/wiki/Wiki.jsp?page=CommonHurdlesAndDifficultiesYouMayEncounterDuringEJB3Development that says to make sure you don't have the class in more than one jar. I've checked, and it only appears in one of my jars.

      When I step through the code, it returns a $Proxy, which contains h, a StatelessRemoteProxy. Within the proxy it sees the appropriate jar. And in the EJBMetaData, it has the appropriate interface, GeoFeatureManager.

      So, I don't really see what I'm doing wrong. Hopefully somebody else can point out my mistake.

      Thanks!

        • 1. Re: ClassCastException on Stateless Remote Bean
          holmes.j

          This one was stupid. I was originally casting back to the bean. That won't work, so I changed it to the interface. Except I only changed the declared local variable, I missed the cast.

           GeoFeatureManager geoFeatureManager = (GeoFeatureManagerBean) object;


          should have been

          GeoFeatureManager geoFeatureManager = (GeoFeatureManager) object;