title: Upgrade Hibernate version in JBOSS
body: <p>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).</p>
  
  <p>Then I made my deployment "scoped" by including in the EAR a jboss-app.xml file containing the following:</p>
  
  <pre><code>&lt;jboss-app&gt;
    &lt;loader-repository&gt; 
    com.example:archive=unique-archive-name 
       &lt;loader-repository-config&gt; 
       java2ParentDelegation=false 
       &lt;/loader-repository-config&gt; 
    &lt;/loader-repository&gt;
  &lt;/jboss-app&gt;
  </code></pre>
  
  <p>And, as usual, I declare my persistence provider in the persistence unit to be Hibernate, as follows:</p>
  
  <pre><code>&lt;persistence&gt;
     &lt;persistence-unit name="myapp"&gt;
        &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
     ...
  </code></pre>
  
  <p>But then, the worst happens. On deployment, the server throws a ClassCastException when it tries to cast from <strong>org.hibernate.ejb.HibernatePersistence</strong> to the JPA interface <strong>javax.persistence.spi.PersistenceProvider</strong> (which IS implimented by HibernatePersistence).</p>
  
  <p>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.</p>
  
  <p>If I don't ship my own JPA API, then the deployment fails with a ClassNotFoundException when JBoss tries to find some JPA class.</p>
  
  <p>Any idea on why is this casting failing?</p>
  
  <p>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 the menctioned Hibernate version.</p>