3 Replies Latest reply on Jul 14, 2006 11:28 AM by Steve Claflin

    Look-up ejb class getInterfaces shows my home interface, but

    Steve Claflin Newbie

      I'm trying to instantiate a simple bean:

      The class object for the bean as looked up says it implements my home interface, but in reality it does not (see jsp code below):

       Object theBean =
       out.write("<hr /><h3>looked up DemoBean</h3><hr />");
       Method!! methods = theBean.getClass().getDeclaredMethods();
       for (int i = 0; i < methods.length; i++) {
       out.write("<li>" + methods!i!.getName() + "</li>");
       Class!! interfaces = theBean.getClass().getInterfaces();
       for (int i = 0; i < interfaces.length; i++) {
       out.write("<li>" + interfaces!i!.getName() + "</li>");
      // list includes my home interface: ejb.demo.DemoHome
       out.write("<hr />" +
       ((theBean instanceof ejb.demo.DemoHome) ?
       " is " : " is not " ) +
       "an instance of DemoHome");
       // note: it is not
       out.write("<hr />" +
       isAssignableFrom(ejb.demo.DemoHome.class) ) ?
       " is " : " is not " ) +
       "assignable from DemoHome");
       // note: it is not
       out.write("<hr />about to try cast");
       ejb.demo.DemoHome dhome = (ejb.demo.DemoHome) theBean;
      //fails with ClassCastException

      Is this a some sort of scoping issue? (Note that I created this thru NetBeans 5.0, which wanted me to have two separate projects within the same application -- the above file is in the WebModule, while the EJB classes are in the EJBModule)

      Note that in the above code ! are used for array brackets, because, try as I might, I could not get bbCode to be disabled, at least in the preview (ditto for HTML actually, but in bbCode mode that didn't seem to matter)

        • 1. Re: Look-up ejb class getInterfaces shows my home interface,
          Steve Claflin Newbie

          An addendum:

          After posting, I tried creating a new bean and it worked fine. I had been noticing startup errors for InstanceAlreadyExistsException, so I wondered if I had been using a cached version of the original bean instead of the latest. So I edited my new bean by adding another method, redeployed it, and it now fails the same way.

          So I'm thinking that my JSP is wanting to use one definition of my class, and JBoss is supplying a different version of it, thus the ClassCastException (I have a vague recollection that Java is smart enough to see that two classes that coincidentally have the same name can't be cast to one another).

          So, if that is the case, how do I flush out the old bean definitions? (I already tried deleting everything in the server\default\tmp\deploy directory, but that didn't help)

          • 2. Re: Look-up ejb class getInterfaces shows my home interface,
            jaikiran pai Master

            Looks like the class is being packaged in more than one archive. Have a look at:


            Use the jmx-console method described in the link above, to try and figure out if that's the case.

            • 3. Re: Look-up ejb class getInterfaces shows my home interface,
              Steve Claflin Newbie

              Thanks, that helped me resolve the issue (I believe).

              It turns out that with NetBeans you have to be careful not to deploy the indiviual projects that make up an enterprise application. You must only deploy the entire app. Otherwise you end up with multiple copies of the beans.

              The jmx-console method described in the page you mentioned showed me that I had three instances of the bean, one from the web module war, one from the EJB module jar, and one from the enterprise application ear. So I went to the deploy directory and deleted the war and jar, leaving only the ear file.

              After that, the bean I added later works now. For some reason, I can't get the original bean to work, but that I can resolve later.