liveBook · Manning

Hibernate OGM

As explained in Java Persistence with Spring Data and Hibernate epub

Hibernate OGM is a Hibernate module that provides JPA-based object or grid mapping to nonrelational data stores.

Hibernate OGM extends JPA-based persistence beyond relational databases to NoSQL stores. It reuses the Hibernate Core engine, JPA APIs, and JPQL while mapping entities to document-, graph-, or other nonrelational data stores. section 18.1 section 2.1

A typical application follows this path:

  • Add the Hibernate OGM bill of materials, a datastore-specific module such as hibernate-ogm-mongodb, and a JTA implementation through Maven. section 18.2.1
  • Configure the persistence unit with HibernateOgmPersistence, select the MongoDB provider, name the database, and optionally create it. section 18.2.1
  • Use JPA entities and EntityManager operations inside transaction boundaries, including reads performed with find. section 18.2.3
  • Query the NoSQL data through JPQL rather than a datastore-specific query language. section 18.2.3

Switching from MongoDB to Neo4j

A persistence application can move from MongoDB's document-oriented store to Neo4j's graph-oriented store by changing required Maven dependencies and persistence-unit configuration while leaving JPA and JPQL code unchanged. section 18.2 section 18.4

Listing 18.2 The persistence.xml configuration file
Path: Ch18/hibernate-ogm/src/main/resources/META-INF/persistence.xml
 
<persistence-unit name="ch18.hibernate_ogm">                                #1
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>      #2
    <properties>
        <property name="hibernate.ogm.datastore.provider" value="mongodb"/> #3
        <property name="hibernate.ogm.datastore.database"                   #4
                  value="hibernate_ogm"/>                                   #4
        <property name="hibernate.ogm.datastore.create_database"            #5
                           value="true"/>                                   #5
    </properties>
</persistence-unit>

Inspect a compact persistence.xml configuration that selects Hibernate OGM, MongoDB, the target database, and database creation behavior. section 18.2.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains Maven dependencies, persistence configuration, transaction boundaries, JPA operations, JPQL queries, and datastore switching.
Examples
Uses MongoDB collections, persisted User, Item, and Bid entities, EntityManager.find, JPQL ordering, and a Neo4j migration.
What it assumes
Assumes familiarity with JPA and Hibernate persistence while demonstrating NoSQL configuration and datastore portability.
What you can do after
Build it from scratch with Maven, configure MongoDB persistence, execute transactional JPA and JPQL operations, and switch to Neo4j.
How it connects
Connects JPA, Hibernate Core, JPQL, transactions, MongoDB, Neo4j, and NoSQL database models.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.