0 Replies Latest reply on Sep 2, 2011 4:08 AM by eduterio1

    Deploy EAR on JBoss with its own version of HIBERNATE

    eduterio1

      Hello,

       

      I am having a hard time when trying to ship inside my EAR my own version of Hibernate (and not the one that JBoss brings by default).

       

      To do it, I ship my Hibernate core and entitymanager packages inside the EAR, and try to isolate my classes from the JBoss' ones by making my deployment "scoped" including in the EAR a jboss-app.xml file containing the following:

       

      <jboss-app>
        <loader-repository>com.example:archive=unique-archive-name
           <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
        </loader-repository>
      </jboss-app>

       

       

      As I want to use Hibernate through JPA, I declare my persistence provider in the persistence unit to be Hibernate, as follows:

       

      <persistence>
         <persistence-unit name="myapp">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
         ...

       

       

      But then, the worst happens. On deployment, the server throws a ClassCastException when it tries to cast from org.hibernate.ejb.HibernatePersistence to the JPA interface javax.persistence.spi.PersistenceProvider (which, as you may know, IS indeed implimented by HibernatePersistence class).

       

      This is kind of WEIRD, because I am shipping the JPA API also in my EAR, so, given that the classes of the EAR have priority to those of JBoss, it should have no problem when casting from HibernatePersistence to PersistenceProvider, since they "should be" on the same class loader.

      If I don't ship my own JPA API, then the deployment fails with a ClassNotFoundException when JBoss tries to find some JPA class.

       

      Any idea on why is this casting failing?

       

      I am using JBoss 5.1.0, and trying to use Hibernate 3.5.6.Final. The JPA API version is the one imported transitively by Maven through the menctioned Hibernate version.