title: Exclude JPA 2.0 from JBoss 7.1 in order to use hibernate 4.3
body: <p>I want to use hibernate 4.3 for its multitenancy features in JBoss 7.1.</p>
  
  <p>I managed to include it in my war by adding the following lines in jboss-deployment-structure</p>
  
  <pre><code>&lt;exclusions&gt;
     &lt;module name="org.hibernate" /&gt;
  &lt;/exclusions&gt;
  </code></pre>
  
  <p>and adding a dependency to hibernate core and entity manager in my pom.xml</p>
  
  <p>This made hibernate 4.3 to load but unfortunately I got an error </p>
  
  <pre><code>java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
  </code></pre>
  
  <p>which is due to JPA 2.0 being loaded when hibernate 4.3 is using JPA 2.1</p>
  
  <p>I have seen these threads and tried what they suggest
  <a href="https://stackoverflow.com/questions/21078551/excluding-jpa-subsystem-from-jboss-eap-6-1-trying-to-use-jpa-2-1-in-jboss-eap">Excluding JPA Subsystem from JBoss EAP 6.1 - Trying to use JPA 2.1 in JBoss EAP 6.1</a>, <a href="https://stackoverflow.com/questions/10231575/jboss-as7-automatically-loading-jpa">JBoss AS7 Automatically Loading JPA</a>, <a href="https://stackoverflow.com/questions/21157123/hibernate-4-3-0-final-spring-data-jpa-1-4-3-release">Hibernate 4.3.0.Final &amp; Spring Data JPA 1.4.3.RELEASE</a>.</p>
  
  <p>I added a persistence.xml with </p>
  
  <pre><code>&lt;property name="jboss.as.jpa.managed" value="false" /&gt; 
  </code></pre>
  
  <p>excluded hibernate jpa 2.0 from Spring Data</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
      &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
      &lt;version&gt;${spring-data.version}&lt;/version&gt;
      &lt;exclusions&gt;
          &lt;exclusion&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;
          &lt;/exclusion&gt;
      &lt;/exclusions&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Removed JPA subsystem completely from JBoss standalone.xml, without any success.</p>
  
  <p>The only thing that did the trick was to exclude the whole javaee.api in jboss-deployment-structure, as suggested in another thread</p>
  
  <pre><code>&lt;exclusions&gt;
      &lt;module name="javax.persistence.api"/&gt;
      &lt;module name="javaee.api"/&gt;
  &lt;/exclusions&gt;
  </code></pre>
  
  <p>but this causes many problems to the rest of my code.</p>
  
  <p>UPDATE: my jboss-deployment-structure.xml is now like this</p>
  
  <pre><code>&lt;jboss-deployment-structure&gt;
  &lt;deployment&gt;
      &lt;exclusions&gt;
          &lt;module name="org.slf4j" /&gt;
          &lt;module name="org.slf4j.impl" /&gt;
          &lt;module name="org.apache.log4j" /&gt;
          &lt;module name="javax.persistence.api" /&gt;
          &lt;module name="org.hibernate" /&gt;
      &lt;/exclusions&gt;
      &lt;dependencies&gt;
          &lt;module name="org.jboss.ironjacamar.jdbcadapters" /&gt;
          &lt;module name="org.hornetq" /&gt;
          &lt;module name="org.hornetq.ra" /&gt;
          &lt;module name="org.jboss.ejb3" /&gt;
          &lt;module name="org.jboss.ejb-client" /&gt;
      &lt;/dependencies&gt;
  &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p>As you see I have tried many things without luck, so if anyone has another idea it is most welcome.</p>