Hibernate OGM provider for Spring configuration

后端 未结 2 1525
旧时难觅i
旧时难觅i 2021-01-01 06:02

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

2条回答
  •  伪装坚强ぢ
    2021-01-01 06:07

    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
        
    

提交回复
热议问题