2 Replies Latest reply on Jun 15, 2007 9:17 AM by felderr

    Isolated Classloader with JPA (java.lang.ClassCastException:

    felderr

      Each EAR Deployment is isolated in a seperate Classloader. This is due to the fact, that we use different Hibernate versions on different EAR Deployments.

      We specifiy the isolation in the jboss-app.xml file as following:
      <jboss-app>
      <loader-repository>classloader:loader=earfilename
      <loader-repository-config>java2ParentDelegation=false
      </loader-repository-config>
      </loader-repository>
      </jboss-app>

      While migrating from native Hibernate access to JPA access we consider problems with this isolated classloaders, as the EntityManagerFactory is built from the Class org.jboss.ejb3.entity.PersistenceUnitDeployment. This class is in the Library jboss-ejb3.jar which is located in the lib directory of JBoss.

      The problem is, that we fall back to the lib directory of JBoss and therefore the Hibernate Version that lies within this directory is used as persistence provider for JPA.

      So we have two different versions of hibernate, one in the lib directory and one in the EAR file. This leads to the problem that we get a ClassCastException when setting the Dialect as the Dialect Object was used from the hibernate Version within the EAR file, the DialectFactory was used from the hibernate version within the lib directory.

      Any ideas (especially to the JBoss Members) how to solve this issue?

      Thx Rene

        • 1. Re: Isolated Classloader with JPA (java.lang.ClassCastExcept

          Well, I am not a jboss and memeber and everything but an expert on class loading but shouldn't you be able to simply remove the (now uneeded) Hibernate libs from the EAR?

          Regards

          Felix

          • 2. Re: Isolated Classloader with JPA (java.lang.ClassCastExcept
            felderr

            If I remove them everthing would work fine! But that would lead to the problem that all EAR Projects on the production server use the same Hibernate version. On our production machine we have about 20 projects using different versions of hibernate (some still use hibernate 2).

            Some other projects are evaluating toplink. I don't want to set up a new JBoss Instance for every version of any JPA Provider in use on our server.

            If that would be the case I would reccomend to step back to using hibernate without JPA.

            You could also remove the classloader isolation with all the drawbacks you will have.

            But thanks for the response!