1.2. Requirements

1.2.1. Dependencies

Second level caching with JBoss Cache 2 requires the use of JBoss Cache 2.1.0 or later. The core JBoss Cache project is used; the related PojoCache project/library is not needed. The following jars, included with the JBoss Cache distribution, need to be on the classpath:

  • jbosscache-core.jar

  • commons-logging.jar

  • jboss-common-core.jar

  • jgroups.jar

JBoss Cache also needs to have the classes in the javax.transaction package on the classpath, but those are already included in the Hibernate distribution.

The hibernate-jbosscache2.jar that is included with the Hibernate distribution also needs to be on the classpath.

A JBoss Cache configuration file, and usually a JGroups configuration file[1], need to be on the classpath. The hibernate-jbosscache2.jar includes standard configuration files in the org.hibernate.cache.jbc2.builder package. The jbc2-configs.xml file is for JBoss Cache and the jgroups-stacks.xml file is for JGroups. See Section 3.2, “Configuring JBoss Cache” and Section 3.3, “JGroups Configuration” for more details on these files. Users can create their own versions and tell the SessionFactory to use them; see Section 3.1, “Configuring the Hibernate Session Factory” for details.

1.2.2. JTA Transactional Support

JBoss Cache requires integration with a JTA TransactionManager in order to meet the requirements of the second level caching use case. This means your Hibernate application must be configured to use JTA:

  • You must configure a hibernate.transaction.manager_lookup_class.

  • You must configure a hibernate.transaction.factory_class, specifying a transaction factory that supports JTA. In practice, this means org.hibernate.transaction.JTATransactionFactory if you are using JTA directly, or org.hibernate.transaction.CMTTransactionFactory if you are accessing Hibernate via a CMT session bean.

  • Finally, make sure hibernate.current_session_context_class is either unset (backwards compatiblity), or set to "jta".

See the Hibernate Reference Documentation for an in-depth discussion of using Hibernate with JTA

[1] JGroups is the group communication library used by JBoss Cache for intra-cluster communication.