1 Reply Latest reply on Apr 25, 2015 1:40 PM by wdfink

    EJB Lookup causing ClassCastException JBoss EAP 6.2

    smasilamani

      Hi

       

       

      We have two EAR applications and we are trying to look up an EJB resides on EAR1 from EAR2 application and getting ClassCastException for one of the classes in EJB1.jar

       

       

      E.g.

       

       

      EAR1:

           EJB1.jar

           WAR1.war

       

       

      EAR2:

           EJB2.jar

           WAR2.jar

       

       

      One of the classes from EJB2.jar is trying to look up an EJB from EJB1.jar and I can see that EJB look up is working fine but when we call one of the methods on EJB1 ,we are getting ClassCastException for one of the utility classes (BranchSummarry.java)

       

       

      This is what I have tried with no luck:

      1. Created a module for EAR1.EJB1.jar inside module folder and added it as a dependancy in Jboss-deployment-structure.xml on EAR2 but again same error.

      2.Added the EJB1.jar to the lib dir of EAR2 directly and again getting same error

       

       

       

      Another interesting thing in jboss-deployment-structure.xml of EAR2, is that unless I add export =true,I am getting ClassNotFoundException for  BranchSummary.java from EJB2 module,I do not understand why export=true works but adding it throws ClassCastException.

       

       

      As a last try,I enabled jvm verbose to see classes loaded and see which classloader is loading that class and found that only two loader do that,one loaded from EAR1.ear and another is from module that I created and if I put that  jar inside EAR2 again I see one loaded as part of EAR1 and another loaded as part of EAR2.

       

       

      Your help is much appreciated.

        • 1. Re: EJB Lookup causing ClassCastException JBoss EAP 6.2
          wdfink

          Sounds like you pack one of the classes in multiple jar files.

          As the class is identified by the class and classloader combination you see a CCException if the invocation is made with "call by reference".

          You might use a Remote interface and check that the invocation is conform to the spec "call by value" or you add the shared classes to a module and depend on it.