Quite a few folks have asked about the new Hibernate Core modules introduced with the 3.3 release: what each is for, when to use which, etc. I wanted to take a bit to describe what each of the main modules is for and when/how you would use certain combinations. (These modules also define maven artifacts; all Hibernate Core artifacts use org.hibernate groupId).
The modules
- hibernate-core - defines the basic functionality of Hibernate. It is expected that this module will be split up further in future releases.
- hibernate-jmx - defines the functionality for Hibernate to integrate with JMX servers. Both the org.hibernate.jmx.HibernateService and org.hibernate.jmx.StatisticsService are defined in this module.
- hibernate-ehcache - defines the integration for using EhCache as Hibernate's second level cache
- hibernate-jbosscache - defines the integration for using JBossCache as Hibernate's second level cache, based on the 1.x versions of JBossCache. This integration should be considered deprecated in favor of the newer 2.x based integration...
- hibernate-jbosscache2 - defines the integration for using JBossCache as Hibernate's second level cache, based on the 2.x versions of JBossCache
- hibernate-oscache - defines the integration for using OSCache as Hibernate's second level cache
- hibernate-swarmcache - defines the integration for using SwarmCache as Hibernate's second level cache
- hibernate-c3p0 - defines the integration for using the c3p0 connection pool as Hibernate's ConnectionProvider
- hibernate-proxool - defines the integration for using the proxool connection pool as Hibernate's ConnectionProvider
- hibernate-parent - this acts as the parent pom for all the Hibernate modules. Users will generally never use nor need to know about this module. I wanted to mention it here simply because it might be useful for folks developing extensions to Hibernate.
- hibernate-testing - defines the basic infastructure used by the Hibernate testsuite for building SessionFactories and managing Sessions. Was broken out as a separate module because I thought users might find it useful as well for testing Hibernate-related code.
There are other modules, but the above ones are the ones developers will usually need to use (the others include things like DocBook sources).
Using
The minimum dependency set-up with Javassist and using log4j as logging library would be:
<dependencies> <!-- the dependency on the hibernate-core module (see above) --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.3.1.GA</version> </dependency> <!-- want to use Javassist as Hibernate's bytecode provider, so we depend on it here. --> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.4.GA</version> </dependency> <!-- Logging set up --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.2</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> </dependencies>
To use cglib instead of Javassist, we would have this instead:
<dependencies> <!-- the dependency on the hibernate-core module (see above) --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.3.1.GA</version> </dependency> <!-- Here we are using cglib instead of Javassist (Hibernate 'repackages' cglib to avoid name clashes) --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-cglib-repack</artifactId> <version>2.1_3</version> </dependency> <!-- Logging set up --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.2</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> </dependencies>
Now, lets add support for second level caching with EhCache:
<dependencies> <!-- the dependency on the hibernate-core module (see above) --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.3.1.GA</version> </dependency> <!-- Here we are using cglib instead of Javassist (Hibernate 'repackages' cglib to avoid name clashes) --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-cglib-repack</artifactId> <version>2.1_3</version> </dependency> <!-- Logging set up --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.2</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> <!-- Here is the bit enabling EhCache support --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId> <version>3.3.1.GA</version> </dependency> </dependencies>
As we stated above, we said that the hibernate-ehcache module defines the integration with EhCache. It also defines a dependency on EhCache itself, which maven pulls into our dependencies here transitively
. See the maven documentation for information about how this all works. The point is simply that we just need to depend on the hibernate-ehcache module and the other deps need to use EhCache are handled for us.