14 Replies Latest reply on May 28, 2012 9:59 AM by Ales Justin

    Overriding server libs in an EJB inside an EAR - 5.1.0.GA

    Rodrigo Uchoa Novice

      Hi everyone!

       

      This is something I've been struggling for quite some time. That is, how to change the classloader behavior in an EAR deploy. I've read a lot of posts and docs around the internet, but nothing seems to be exactly my case.

       

      It all started with the need to update Hibernate libs in JBoss 5.1.0.GA (from the bundled 3.2.4 to 3.3.1). Using the jboss-classloading.xml file it worked fine when we use a standalone .WAR deploy with the hibernate libs inside "WEB-INF/lib" directory. When we switched to an .EAR deploy, it stopped working. Our .EAR structure looks like this:

       

      EAR

      |

      |---- lib //all libs, including hibernate's, are here

      |

      |---- META-INF

      |             |---- jboss-classloading.xml

      |

      |---- EJB_Module //persistence-unit defined here, along with EJB business classes

      |

      |---- WAR_Module

                    |---- WEB-INF

                                |---- jboss-classloading.xml

       

       

      The EAR jboss-classloading.xml:

       

      <classloading xmlns="urn:jboss:classloading:1.0"
          domain="app.ear"
          export-all="NON_EMPTY"
          import-all="true"
          parent-first="false">
      </classloading>
      

       

       

      The WAR's jboss-classloading.xml:

       

      <classloading xmlns="urn:jboss:classloading:1.0"
          domain="app.war"
          parent-domain="app.ear"
          export-all="NON_EMPTY"
          import-all="true">
      </classloading>
      

       

       

      Now to the problem... Let's suppose I have two different .EAR projects with the exact same structure described above. When I deploy both of them to the same JBoss AS instance, one of them always have classloading issues with the hibernate libs when server is starting up. More specifically, we get "ClassCastException" with a hibernate interceptor we have:

       

      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: sinpi-pu] Interceptor class does not implement Interceptor interface: br.gov.dpf.sinpi.core.util.HistoricoInterceptor
          at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:811)
          at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
          at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
          at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
          at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
          at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:85)
          at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:592)
          at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
          at org.jboss.seam.Component.callComponentMethod(Component.java:2283)
          at org.jboss.seam.Component.callCreateMethod(Component.java:2198)
          at org.jboss.seam.Component.newInstance(Component.java:2158)
          ... 75 more
      Caused by: java.lang.ClassCastException: br.gov.dpf.sinpi.core.util.HistoricoInterceptor
          at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:793)
      

       

       

      My assumption is that different "org.hibernate.Interceptor" classes loaded by different classloaders are causing this mess. This problem only occurs when we deploy two EAR's at the same time. I even tried to change the "ear-deployer-jboss-beans.xml" isolated configuration, but it didn't work. What I need is that both EAR's use the newer hibernate libs bundled inside each "ear/lib" directory.

       

      Any ideas would be appreciated.