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*"






















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






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



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="">


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




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

             <!-- Insert resources here -->




             <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=""/>

             <module name=""/>

             <module name=""/>

             <module name=""/>

             <module name=""/>

             <module name=""/>

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

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

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

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





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="" slot="3">





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

             <!-- Insert resources here -->




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  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>


                       <property name=""





Your application should now run using Hibernate 3.



[1] Drop in a Hibernate 3.6.6.Final module:

[2] JBoss Modules, Introduction:

[3] How to Run JBoss Jandex: