Hibernate OGM with JPA and Infinispan on Wildfly 8.2

Flemming Harms

Recently, we had a task where we had to choose whether we should use the current architecture.

“Entity->JPA->Hibernate ORM->Cache->SQL”

Alternatively, whether to use Hibernate OGM as a persistence layer to a NoSQL provider.

“Entity->JPA->Hibernate OGM->NoSQL” There were many strong arguments for using Hibernate OGM, but as always when you encounter new technology, you are trying to determine the work and impact based on documentation, forums, blogs or short tutorials typically based on the latest version. However, another story is getting it to work with a running application, which is a few versions behind the latest and greatest.

So I decided to create a POC with our current technology stack the almighty Wildfly 8.2, Hibernate ORM, Infinispan and now Hibernate OGM 4.1.3.Final.

<a name=”thegoal”>./ The goal is

  • Install Hibernate OGM 4.1.3 into Wildfly 8.2
  • Deploy an application using Hibernate OGM

./ What I found out

I started with the Hibernate OGM documentation and the first question I encountered, was it even possible to get it to work with Infinispan 6.0.2?

Fortunately, this is really easy to do. When you install the modules, it will co-exist with the current version of Infinispan 6, but the downside is you will have to maintain two sets of configuration files if you want to customize Infinispan 7. The good news is that the module will work out of the box with the default configuration.

./ The solution

I have created a small solution where I create a simple remote queue service, where you are able to subscribe, unsubscribe and post/consume messages.

In the package : >org.hibernate.ogm.infinispan7.jpa.example.model you will find the JPA entities.

org.hibernate.ogm.infinispan7.jpa.example.dao you will find the service that is responsible for persisting the entities.

I have created an arquillian test to show it actually work.

The main pom file takes care of all the setup and installation of Hibernate OGM. I use the maven-dependency-plugin for this, but if you want to use a DIY method, follow the manual steps


There are a few issues with the persistence.xml that you have to be aware of.

  • The provider “HibernateOgmPersistence” bypasses the autodetection of entities, and this is the reason why they are specified in the persistence unit. This is a known issue. OGM-818
  • Adding the property “” & “” gave a considerable performance improvement.
  • Want to try how easy and transparent it is to switch between Hibernate ORM and OGM. Change the persistence unit name in the class com.fharms.ogm.infinispan7.jpa.example.dao.RemoteEventDao to “RemoteEventQueueSQL”
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="" xmlns:xsi="" version="2.0" xsi:schemaLocation="">
  <persistence-unit name="RemoteEventQueue" transaction-type="JTA">
       <!-- When using HibernateOgmPersistence provider it does not scan for entity classes -->
             <!-- Changing from filebase to Infinispan gave huge performance from 3 sec to 177 ms -->
             <property name="" value="infinispan"/>
             <property name="" value="false"/>
            <property name="hibernate.transaction.jta.platform"
                        value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
            <property name="hibernate.ogm.datastore.provider"
                        value="infinispan" />
            <property name="hibernate.ogm.infinispan.configuration_resource_name" value="com/fharms/ogm/infinispan7/jpa/example/dao/infinispan-local.xml"/>

      <!-- If you want to run with Hibernate ORM and SQL database, change the persistence unitname
        in the class com.fharms.ogm.infinispan7.jpa.example.dao.RemoteEventDao
      <persistence-unit name="RemoteEventQueueSQL" transaction-type="JTA">
            <property name="" value="create" />
             <!-- Changing from filebase to Infinispan gave huge performance from 3 sec to 177 ms -->
             <property name="" value="infinispan"/>
             <property name="" value="false"/>

./ Where do I find the code.

Jump to the source code on github

./ What I learnt

It was straightforward to use for this use case, but with all software, there are always issues. So don’t expect anything less with Hibernate OGM.

There are some issues you have to be aware of when installing for the first time, as described in this post, but the Hibernate OGM documentation is a good place to start. The documentation provided walks you through the installation and setup.

Then source code is also a good place to look and I learned a great deal by looking into the unit tests.

So did we choose Hibernate OGM? Well, not this time because we couldn’t justify taking the risk with introducing a new framework at this point. However, this is not the last time I’ll be working with Hibernate OGM; that’s for sure.


./ Manual install the Hibernate OGM & Infinispan

This small guide shows how you can manually update Wildfly with Hibernate OGM & Infinispan module.

Your Wildfly is now updated and ready for Hibernate OGM.