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
