0

Our project is using Neo4j as a long term datastore.

We have a use-case to use a data-grid to relieve Neo4j from redundant queries, be able to do queries directly in RAM, and be notified when some data in memory changes. For that, we have seen that Infinispan is very interesting.

On top of that, we have seen that Hibernate OGM can support both Infinispan and Neo4j datastores.

Is it possible to use the same data model to map our pojos to both Neo4j and Infinispan with Hibernate OGM ?

rico
  • 1,843
  • 2
  • 24
  • 41

1 Answers1

1

Yes, if you create two different factories.

If you stick to JPA, you can use the same entity classes in both persistence unit configurations but you won't be able to use a single factory to work on both the datastores at the same time.

This is a simple example taken from one of the tests we have in the repository that creates an entity manager for Hibernate ORM and one for Hibernate OGM:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
         version="2.0">

  <persistence-unit name="ogm" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
  </persistence-unit>

  <persistence-unit name="no-ogm" transaction-type="RESOURCE_LOCAL">
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
    </properties>
  </persistence-unit>

</persistence>

You need to set the right properties for your use case.

You can get the right factory using:

EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ogm" );

You can do something similar with annotations as well.

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30