views:

36

answers:

1

Hello.

I'm struggling with JBOss and I'm stuck on a problem which seems trival to fix but it turns out I can't. When I try to deploy a simple java web app I encounter an exception:

org.hibernate.ejb.HibernatePersistence cannot be cast to avax.persistence.spi.PersistenceProvider

I know that this is a problem with having more then one persistence.jar. So in my pom I did something like that:

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.4.0.GA</version>
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate</groupId>
                    <artifactId>ejb3-persistence</artifactId>
                </exclusion>
</dependency>

But I'm unlucky with it. I still get the error. Could anybody help me kindly to solve this task?

Agata

A: 

It looks like you want to package your own version of Hibernate within your application. This is possible but you'll have to setup classloader scoping for your application. From ClassLoadingConfiguration:

Isolation with Overriding Server Classes

Use the following constructs to enabled scoped class loading with the deployment classes overriding the server classes.

...

For jboss-web.xml:

<jboss-web>
   <class-loading java2ClassLoadingCompliance="false">
      <loader-repository>
         com.example:archive=unique-archive-name
         <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
      </loader-repository>
   </class-loading>
 ...

In other words, either include all your Hibernate libraries and disable parent class loader delegation or exclude them all and use the one from JBoss.

See also

Pascal Thivent
Hello,Thank you very much for your response. I resolved my problem by just excluding all hibernate jars and persistence from my pom.xml while building into war and it works just fine.But thank you again for your time and help!
Agata