AS 7's default persistence provider is Hibernate 4.   It is provided as a module.   A different persistence provider can be added to the server via a module definition.  Lets add Hibernate 3 to the server.   Lets find the Hibernate 4 module definiton and use it as the model to add a Hibernate 3 module.  Look for hibernate in your  ${JBOSS_HOME}/modules directory.

 

          cd ${JBOSS_HOME}

         find modules -name "*hibernate*"

 

 

         modules/javax/persistence/api/main/hibernate-jpa-2.0-api-1.0.1.Final.jar

          modules/javax/persistence/api/main/hibernate-jpa-2.0-api-1.0.1.Final.jar.index

          modules/org/hibernate

          modules/org/hibernate/main/hibernate-commons-annotations-4.0.1.Final.jar

          modules/org/hibernate/main/hibernate-entitymanager-4.0.1.Final.jar.index

          modules/org/hibernate/main/hibernate-core-4.0.1.Final.jar

          modules/org/hibernate/main/hibernate-entitymanager-4.0.1.Final.jar

          modules/org/hibernate/main/hibernate-core-4.0.1.Final.jar.index

          modules/org/hibernate/main/hibernate-commons-annotations-4.0.1.Final.jar.index

          modules/org/hibernate/main/hibernate-infinispan-4.0.1.Final.jar

          modules/org/hibernate/main/hibernate-infinispan-4.0.1.Final.jar.index

          modules/org/hibernate/envers/main/hibernate-envers-4.0.1.Final.jar

          modules/org/hibernate/envers/main/hibernate-envers-4.0.1.Final.jar.index

          modules/org/hibernate/validator/main/hibernate-validator-4.2.0.Final.jar

          modules/org/hibernate/validator/main/hibernate-validator-4.2.0.Final.jar.index

          modules/org/jboss/as/jpa/hibernate

          modules/org/jboss/as/jpa/hibernate/main/jboss-as-jpa-hibernate4-7.1.1.Final.jar

          modules/org/jboss/as/jpa/hibernate/4/jboss-as-jpa-hibernate4-7.1.1.Final.jar.index

 

As you can see there are quit a few hibernate achives present.  Lets ferret out the one that is of interest to us.  But first I should tell you  there is a directory naming convention for modules.  Part or all of the package name of the APIs that make up the module's content is used as the directory path.  The dot-separated segments of the package's name are given as the directory name.  In addition a path ending with the name "main" indicates that it  is to be used as the default module.  When the last name is other than "main" it is the definition of a "slot" name.  The "slot" name is called out in the application to reference the module to be use.

 

With this information we can summize from the directory and jar file names that, modules/javax/persistence/api/main/hibernate-jpa-2.0-api-1.0.1.Final.jar is the java spec API for JPA, modules/org/hibernate/main/hibernate-commons-annotations-4.0.1.Final.jar are annotation related APIs, modules/org/hibernate/envers/main/hibernate-envers-4.0.1.Final.jar are support APIs, modules/org/hibernate/validator/main/hibernate-validator-4.2.0.Final.jar are the validator APIs, and modules/org/jboss/as/jpa/hibernate/main/jboss-as-jpa-hibernate4-7.1.1.Final.jar are the core APIs in which we are interested.  Lets look at the contents of directory, modules/org/jboss/as/jpa/hibernate/main.

 

 

     ls modules/org/jboss/as/jpa/hibernate/main

 

     jboss-as-jpa-hibernate4-7.1.1.Final.jar       

     module.xml

     jboss-as-jpa-hibernate4-7.1.1.Final.jar.index

 

The directory contains 2 required files and 1 optional file. The JAR archive and the module.xml file are required.   The JAR file contains the APIs being referenced.  The module.xml file is the module descriptor; it describes the structure, content, dependencies, filtering, and other attributes of the module.  We will need to provide a Hibernate 3 jar file and create the corresponding module.xml file.

 

The index file is optional.  It is generated by the jandex utility, which processes Java annotations within a directory or jar file, and saves the resulting metadata in an index file.  This information fosters faster loading of the module.   You do not need to generate this file.  The application server will generated it for you the first time the module is loaded. 

 

Let create a Hibernate 3-7.1.2 module. The jar file can be downloaded from

http://grepcode.com/snapshot/repository.jboss.org/nexus/content/repositories/releases/org.jboss.as/jboss-as-jpa-hibernate3/7.1.2.Final/

 

 

Following the naming convention our Hibernate 3 module should have a directory path name of modules/org/jboss/as/jpa/hibernate.   We need to define an end directory name.  This will be the slot name for this module.  Lets name it 3.

 

     mkdir modules/org/jboss/as/jpa/hibernate/3

 

Copy the jar into this directory

 

    cp /tmp/jboss-as-jpa-hibernate3-7.1.2.Final.jar modules/org/jboss/as/jpa/hibernate/3

 

The module descriptor for this archive will be nearly the same as for Hibernate 4.  Copy the module.xml file from modules/org/jboss/as/jpa/hibernate/main into modules/org/jboss/as/jpa/hibernate/3 and edit it.

 

    cp  modules/org/jboss/as/jpa/hibernate/main/module.xml modules/org/jboss/as/jpa/hibernate/3

 

     <!-- contains the JPA integration classes for Hibernate 4.x -->

     <module xmlns="urn:jboss:module:1.1" name="org.jboss.as.jpa.hibernate">

         <properties>

             <property name="jboss.api" value="private"/>

         </properties>

 

         <resources>

             <resource-root path="jboss-as-jpa-hibernate4-7.1.1.Final.jar"/>

             <!-- Insert resources here -->

         </resources>

 

         <dependencies>

             <module name="javax.annotation.api"/>

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

             <module name="javax.transaction.api"/>

             <module name="org.hibernate" services="import"/>

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

             <module name="org.infinispan"/>

             <module name="org.jboss.as.clustering.infinispan"/>

             <module name="org.jboss.as.controller"/>

             <module name="org.jboss.as.jpa.spi"/>

             <module name="org.jboss.as.jpa.util"/>

             <module name="org.jboss.as.naming"/>

             <module name="org.jboss.as.server"/>

             <module name="org.jboss.jandex"/>

             <module name="org.jboss.logging"/>

             <module name="org.jboss.msc"/>

             <module name="org.jboss.vfs"/>

         </dependencies>

     </module>

 

 

Add attribute slot="3" to the module element.  Change the name of archive from jboss-as-jpa-hibernate4-7.1.1.Final.jar to jboss-as-jpa-hibernate3-7.1.2.Final.jar and save the file.

 

    <module xmlns="urn:jboss:module:1.1" name="org.jboss.as.jpa.hibernate" slot="3">

 

             :

 

         <resources>

             <resource-root path="jboss-as-jpa-hibernate3-7.1.2.Final.jar "/>

             <!-- Insert resources here -->

         </resources>

 

 

The last step is to enable your application to reference the Hibernate 3 module.  Change your  application's persistence.xml file.  Add a property element to the persistence-unit element.  The name of the property is jboss.as.jpa.providerModule.  The value is the name of the module as defined by the name attribute of the module in the module.xml file.  In addition, because this module has a slot name, append ":" followed by the slot name to the reference name.

 

 

     <persistence-unit name="${your unit name}">

              <description>Hibernate 3 persistence unit.</description>

              <jta-data-source>${your jpa src}</jta-data-source>

              <properties>

                       <property name="jboss.as.jpa.providerModule"

                                          value="org.jboss.as.jpa.hibernate:3"/>

               </properties>

     </persistence-unit>

 

Your application should now run using Hibernate 3.

 

References

[1] Drop in a Hibernate 3.6.6.Final module:  http://relation.to/21601.lace

[2] JBoss Modules, Introduction:  https://docs.jboss.org/author/display/MODULES/Introduction

[3] How to Run JBoss Jandex: http://javahowto.blogspot.com/2012/08/how-to-run-jboss-jandex.html