Monday, June 17, 2013

How to use Hibernate OGM in Glassfish 3 ?

After having posted "How to Hibernate OGM in JBoss AS 7 ?", I continue with the reference Java EE 6 applications server, Glassfish in its third version. For this post I use the same code base as for the previous post.

Setting up the application server

You probably know that Glassfish is shipped with Eclipse Link for the JPA2.0 implementation, so the first part is to make Hibernate ORM 4 available. The easiest way is to copy into the %GLASSFISH_HOME%/glassfish/domains/domain1/lib/ folder the required JARs to run Hibernate ORM.
Those JARs are:
  • hibernate-core
  • hibernate-entitymanager
  • hibernate-commons-annotations
  • hibernate-validator
Because OGM is depending on ORM, to avoid any version conflicts I choose to use (as far as possible) the same version of Hibernate JARs that OGM has been built with: 4.2.0 (just hibernate-commons-annotations is in 4.0.2). And that's all, Glassfish is ready.

The application

To use Hibernate ORM, you just have to specify the provider is:
For the OGM part, we just have to copy OGM JARs into the lib folder (mentioned above), those JARs are:

  • hibernate-ogm-core
  • hibernate-ogm-ehcache
  • hibernate-ogm-mongodb
  • ehcache-core
  • mongo-java-driver
For more information about the libraries version, I suggest you to refer to the OGM pom file. If you want to use Infinispan rather than EhCache or MongoDB, just copy both hibernate-ogm-infinispan and infinispan-core .

To switch the application on "OGM mode", it's always the same steps:
  1. use the HibernateOgmPersistence provider
  2. declare the data store provider you want to work with (hibernate.ogm.datastore.provider)
  3. if needed, configure the right properties (host, port, etc. )
At this point, you can run the demo and if it works you'll find in the logs:


  1. Enjoyed your approach to explaining how it works, hope to see more blog posts from you. thank you!

    Hibernate Online Training | Java Online Training

    Hibernate Training in Chennai Java Training in Chennai

  2. They are also in search of a handful of ways to evaluate their teams in extent so that they can pinpoint all the pros and cons including the fields where the need for professional development is