Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude JPA 2.0 from JBoss 7.1 in order to use hibernate 4.3

I want to use hibernate 4.3 for its multitenancy features in JBoss 7.1.

I managed to include it in my war by adding the following lines in jboss-deployment-structure

<exclusions>
   <module name="org.hibernate" />
</exclusions>

and adding a dependency to hibernate core and entity manager in my pom.xml

This made hibernate 4.3 to load but unfortunately I got an error

java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

which is due to JPA 2.0 being loaded when hibernate 4.3 is using JPA 2.1

I have seen these threads and tried what they suggest Excluding JPA Subsystem from JBoss EAP 6.1 - Trying to use JPA 2.1 in JBoss EAP 6.1, JBoss AS7 Automatically Loading JPA, Hibernate 4.3.0.Final & Spring Data JPA 1.4.3.RELEASE.

I added a persistence.xml with

<property name="jboss.as.jpa.managed" value="false" /> 

excluded hibernate jpa 2.0 from Spring Data

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>${spring-data.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Removed JPA subsystem completely from JBoss standalone.xml, without any success.

The only thing that did the trick was to exclude the whole javaee.api in jboss-deployment-structure, as suggested in another thread

<exclusions>
    <module name="javax.persistence.api"/>
    <module name="javaee.api"/>
</exclusions>

but this causes many problems to the rest of my code.

UPDATE: my jboss-deployment-structure.xml is now like this

<jboss-deployment-structure>
<deployment>
    <exclusions>
        <module name="org.slf4j" />
        <module name="org.slf4j.impl" />
        <module name="org.apache.log4j" />
        <module name="javax.persistence.api" />
        <module name="org.hibernate" />
    </exclusions>
    <dependencies>
        <module name="org.jboss.ironjacamar.jdbcadapters" />
        <module name="org.hornetq" />
        <module name="org.hornetq.ra" />
        <module name="org.jboss.ejb3" />
        <module name="org.jboss.ejb-client" />
    </dependencies>
</deployment>
</jboss-deployment-structure>

As you see I have tried many things without luck, so if anyone has another idea it is most welcome.

like image 588
andreadi Avatar asked Apr 25 '14 13:04

andreadi


2 Answers

I would split this problem into two smaller:

1) Make sure you're not transitively depending on JPA 2.0

For this you can use dependency graph visualization tool (NetBeans have one built in, or you can use a maven dependency tree plugin). Another way would be just to skim through the libs, included in your artifact before deploying to JBoss.

2) Ensure correct configuration of JBoss AS 7.1

JBoss AS 7.1 is bundled with Hibernate 4.0.x jars, in order to update them try out this steps as described in the official doc.

  • update the current as7/modules/org/hibernate/main folder to contain the newer version

  • Delete *.index files in as7/modules/org/hibernate/main and as7/modules/org/hibernate/envers/main folders

  • Backup the current contents of as7/modules/org/hibernate in case you make a mistake

  • Remove the older jars and copy new Hibernate jars into as7/modules/org/hibernate/main + as7/modules/org/hibernate/envers/main

  • Update the as7/modules/org/hibernate/main/module.xml + as7/modules/org/hibernate/envers/main/module.xml to name the jars that you copied in

Updated as7/modules/org/hibernate/main/module.xml will look like (note that dependencies won't change):

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="org.hibernate">
    <resources>
        <resource-root path="hibernate-core-4.3.5.Final.jar"/>
        <resource-root path="hibernate-commons-annotations-4.0.4.Final.jar"/>
        <resource-root path="hibernate-entitymanager-4.3.5.Final.jar"/>
        <resource-root path="hibernate-infinispan-4.3.5.Final.jar"/>
    </resources>

    <dependencies>
       .
       .
    </dependencies>
</module>
like image 83
hovanessyan Avatar answered Nov 20 '22 14:11

hovanessyan


Try removing only the javax.persistence.api module along with org.hibernate.

Also, if you want to switch to Hibernate 4.3 for all web applications (which should be backward compatible), switch to a newer version of Hibernate as described here.

Some debugging tips: after generating your JAR files, check explicitly what JPA/Hibernate libraries they contain (by unzipping them). Also in order to check the Hibernate Version you could do it like it is here described.

Also check the structure of the jboss-deployment-structure file, as it seems that the <exclusions> element is neither in a <deployment>, nor in an <sub-deployment> element.

like image 3
V G Avatar answered Nov 20 '22 15:11

V G