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

    Deploy EAR on JBoss with its own version of HIBERNATE

    Eduterio Eduterio Newbie



      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:





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


         <persistence-unit name="myapp">



      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.