I created a Java application that can use SQL Server or Neo4j as a database without touching the application layer, I just modify the provider and the connection information
I add Java Config for Neo4j with OGM Hibernate
@Configuration
@EnableTransactionManagement
@JpaPackagesToScan(Entity.class)
public class RepositoryConfig {
/**
* Neo4J OGM EntityManager config
*/
@Bean
public LocalContainerEntityManagerFactoryBean entityManager(JpaPackagesToScanHolder holder) throws Throwable {
Map properties = new HashMap();
properties.put("javax.persistence.transactionType", "JTA");
properties.put("hibernate.ogm.datastore.provider", "neo4j_embedded");
properties.put("hibernate.ogm.datastore.database", "my-db");
properties.put("hibernate.ogm.neo4j.database_path", "/mnt/graph.db");
properties.put("hibernate.dialect", "org.hibernate.ogm.datastore.neo4j.Neo4jDialect");
LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
entityManager.setPackagesToScan(holder.toStringArray());
entityManager.setPersistenceUnitName("my-pu");
entityManager.setJpaPropertyMap(properties);
entityManager.setPersistenceProviderClass(HibernateOgmPersistence.class);
return entityManager;
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) throws Throwable {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
return transactionManager;
}
}
And added to the pom (for Java 7 project)
org.hibernate.ogm
hibernate-ogm-neo4j
4.1.0.Final