0

How can we integrate Hibernate OGM with Spring Data JPA, so that existing application containing Hibernate ORM can be used with Hibernate OGM.

This is the configuration i'm currently using for Hibernate ORM

 @Bean(name = "jdbc")
 public DriverManagerDataSource getDriverManager() {
 DriverManagerDataSource driverManagerDataSource = new
 DriverManagerDataSource(
 env.getProperty(dataBase + ".url"), env.getProperty(dataBase +
 ".username"),
 env.getProperty(dataBase + ".password"));
 driverManagerDataSource.setDriverClassName(env.getProperty(dataBase +
 ".driver"));
 return driverManagerDataSource;
 }

@Bean(name = "japaImplementation")
public HibernateJpaVendorAdapter getHibernate() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabasePlatform(env.getProperty(dataBase + ".dialect"));
    vendorAdapter.setGenerateDdl(true);
    vendorAdapter.setShowSql(true);
    return vendorAdapter;
}

 @Bean(name = "entityManagerFactory")
 public LocalContainerEntityManagerFactoryBean
 getEntityManagerFactoryBean() {
 LocalContainerEntityManagerFactoryBean factoryBean = new
 LocalContainerEntityManagerFactoryBean();
 factoryBean.setDataSource(getDriverManager());
 factoryBean.setJpaVendorAdapter(getHibernate());
 factoryBean.setPackagesToScan("com.xyz.abc.entity");
 return factoryBean;
 }

2 Answers2

0

I just had a quick glance at Hibernate OGM. It seems it is just a JPA implementation. So Spring Data JPA should work out of the box for it. Although up to now it does not get tested against it.

But it raises the question, why you would want to do that? There are already Spring Data modules for most, if not all of the data stores supported by Hibernate OGM. So why don't you use Spring Data MongoDB directly?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • As my application is already implemented using JPA, I would like to take the advantage of it, by just changing the configuration rather than making code level changes. As Hibernate OGM is JPA implementation, it would be as simple as switching between JPA providers. – Radhakrishna Pemmasani May 18 '17 at 06:46
  • As written this should work out of the box. Spring Data will use whatever EntityManagerFactory it finds, no matter which provider it is coming from. – Jens Schauder May 18 '17 at 07:01
  • yes, but i'm stuck at the configuration part, I know how to integrate hibernate orm, but not sure how to use hibernate ogm to generate entitymanagerfactory. – Radhakrishna Pemmasani May 18 '17 at 07:18
  • so how does your configuration look like? And what error do you get? Please, update your question. – Jens Schauder May 18 '17 at 07:22
0

The projects are more alternatives to each other than something to let one run on top of the other. See this question for arguments from both sides.

Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
  • I agree, but is there a provision for me to run my application just by changing the provider, as the application is already implemented using Hibernate as JPA, and they have provided with the implementation of NoSQL. So, ideally it would be like switching from one implementation of JPA to the other. Isn't it so?? How do we configure Spring Data JPA to use custom provider if any available. – Radhakrishna Pemmasani May 18 '17 at 06:50