Here are a few quick tips when migrating Hibernate 3-based applications to JBoss AS7, covering the options available for JBoss AS 7.0.0.Final.

In previous versions of JBoss AS, a version of Hibernate was always present on the classpath. As a result, applications that used Hibernate directly have traditionally avoided to include it in the deployment in order to avoid classloading conflicts, or have taken additional steps to enforce classloader isolation.

The visibility rules have changed in AS7 due to the new modular classloading model, and so Hibernate libraries are made visible by default only to JPA deployments. The changes may affect existing Hibernate applications, so this is a short breakdown on the available options when running on JBoss AS7. Wherever this is subject to change in future versions, we also provide a succint description of the forthcoming enhancements.

Native Hibernate applications

As of the 7.0.0.Final version of JBoss AS, native (i.e. non-JPA) Hibernate applications can opt between:

  • packaging a Hibernate version of their choice inside the application;
  • adding the 'org.hibernate' module as a dependency to the application (adds Hibernate 4), e.g. by adding to the deployment a META-INF/MANIFEST.MF file that contains the following line:
    Dependencies: org.hibernate
  • creating a custom Hibernate 3 module, and adding it as a dependency to the application,e.g.
    Dependencies: my-custom-hibernate-module
    - noting that future versions of JBoss AS7 may already provide a skeleton Hibernate 3 module.

Application-created persistence units

JPA applications that create an EntityManagerFactory on their own, either using the PersistenceProvider SPI directly or through an intermediary mechanism such as Spring's LocalContainerEntityManagerFactoryBean have the same options as native Hibernate applications, noting that the 'org.hibernate' module may be added by default as a dependency as described here - so you may need to exclude it explicitly if you want to provide a version of your own. Therefore, under typical circumstances such applications can:

  • use the default setup (and use Hibernate 4)
  • package a Hibernate version of their choice and exclude the default 'org.hibernate' module by adding a WEB-INF/jboss-deployment-structure.xml or META-INF/jboss-deployment-structure.xml file (depending whether the deployment is a WAR or not) as follows:
    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
           <module name="org.hibernate"/>
  • create a custom module and using it instead of the default 'org.hibernate';

Container-deployed persistence units

Generally speaking, standard Java EE-applications may ignore the provider implementation and rely on the standard features provided by the container - JBoss AS7 supporting standard JPA 1.0 and 2.0.

However, in future versions of JBoss AS7 it will be possible to use alternative persistence provider implementations - for more details please follow AS7-566.

Back to top