4 Replies Latest reply on Jun 5, 2008 1:02 PM by jaikiran pai

    Upgrading 4.0.4 to 4.2.2; problems accessing EJBs

    Richard Doust Newbie

      Hi. I've not been following the upgrades to JBoss or other supporting technology for some time, even though I own an application that's deployed on JBoss, currently, 4.0.4. I am being forced (on a strict timeline) to upgrade to 4.2.2. In doing so, I'm running into a problem that I don't know how to figure out. I was hoping someone who has been through this might be able to give me a hint.
      I'm deploying an ear that contains 2 wars and several ejb-jars. All of my EJBs are 2.1. When attempting to get access from the code in one of the two wars to some of the EJBs, I'm getting class cast exceptions, whether I attempt to gain access to remote interfaces (using PortableRemoteObject.narrow()), or local. The code works perfectly when deployed to 4.0.4. I can see nothing in the jmx-console to make me think that the beans I'm trying to gain access to are not there, on the contrary, they seem to have deployed just fine. The proxy that I get back from the lookup is causing the exception when I attempt to cast it (in the case of the local interface) and the narrow() call also results in a class cast exception in the case of the remote interface.
      I would be happy to provide more information, I just thought that the fact that it works on 4.0.4 and not on 4.2.2 might make someone go, "Oh, that problem again."
      Thanks in advance for any insight.

        • 1. Re: Upgrading 4.0.4 to 4.2.2; problems accessing EJBs
          jaikiran pai Master

           

          When attempting to get access from the code in one of the two wars to some of the EJBs, I'm getting class cast exceptions, whether I attempt to gain access to remote interfaces (using PortableRemoteObject.narrow()), or local.


          Probably a classloader issue. Are you packaging the remote/local interfaces of the bean in more than one place. See this http://wiki.jboss.org/wiki/ClassCastExceptions for debugging the issue. Check the jmx-console method mentioned in that wiki.

          The other reason might be that the object returned by the lookup is probably not the bean proxy you are interested in. Follow this wiki http://wiki.jboss.org/wiki/DisplayTheJNDITreeWithTheJMXConsole and check the jndi tree contents. Look for the jndi-name that you are using to do the lookup and see what object is bound to that name.


          • 2. Re: Upgrading 4.0.4 to 4.2.2; problems accessing EJBs
            Richard Doust Newbie

            I find the class I'm looking for in the JNDI tree view. It has the proxy name of the class that I also see when in the debugger when I get the instance from the JNDI lookup. In the JNDI tree view it says that it implements the Home Interface that I expect. Yet the cast fails. So, I assume that the problem is multiple copies of the class in the deployment, being seen by different class loaders. I'd like to try to resolve the situation without completely rewriting my build scripts. I looked at the JMImplementation output from displayClassInfo and it tells me that there's only one instance, but I know that I'm deploying the Home interface class in two different places. It's in the ejbjar that contains the implementation of the bean itself, and it's also in the ejb_client.jar that contains the interfaces only. This was my understanding of how to deploy at some point. I've removed it from the ejb_client.jar and am able to get past the class cast exception, but get a linkage error when attempting to invoke a method on the instance, although I'm able to create the instance with no problem.
            The ejb.jar is deployed directly in the ear, and the ejb_client.jar is in the WEB-INF/lib directory of the war.
            Should I move the interfaces to a separate jar file and put it into a new lib directory in the ear, which will then be available to both the implementation in the ejb-jar (having been removed from there) as well as the classes in the war? It seems to me that this is the new deployment mechanism, made possible by J2EE 5.0. Have I got that right?

            • 3. Re: Upgrading 4.0.4 to 4.2.2; problems accessing EJBs
              jaikiran pai Master

              If the classes are needed by both the war and the ejb component (like in this case), then you can package them in a jar and place that jar under the lib folder of the EAR. Those jars will by default be added to the classpath of the application.

              • 4. Re: Upgrading 4.0.4 to 4.2.2; problems accessing EJBs
                jaikiran pai Master

                 

                "jaikiran" wrote:
                If the classes are needed by both the war and the ejb component (like in this case), then you can package them in a jar and place that jar under the lib folder of the EAR. Those jars will by default be added to the classpath of the application.


                And yes, this is available in 4.2.x.