Thursday, January 5, 2017

Spring JPA Hibernate Annotated with custom orm.xml for testing against a HSQL database

Spring JPA Hibernate Annotated with custom orm.xml for testing against a HSQL database



}
DefaultPersistenceUnitManager spum = new DefaultPersistenceUnitManager();
spum.setMappingResources("META-INF/test-orm.xml");
spum.setDefaultDataSource(dataSource);
spum.setPackagesToScan("domain.entity");
spum.afterPropertiesSet();

HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(this.databaseVendor());

LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setPersistenceUnitManager(spum);
factoryBean.setJpaVendorAdapter(vendorAdapter);
final HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("hibernate.hbm2ddl.auto",
      env.getProperty("domain.hibernate.hbm2ddl.auto"));
properties.put("hibernate.dialect",
      env.getProperty("domain.hibernate.dialect"));
properties.put("hibernate.show_sql",
      env.getProperty("domain.hibernate.show_sql"));
properties.put("hibernate.generate_statistics",
      env.getProperty("domain.hibernate.generate_statistics"));
properties.put("hibernate.format_sql",
      env.getProperty("domain.hibernate.format_sql"));
properties.put("hibernate.default_schema", "SEFS_DASHBOARD_SCHEMA");
Constants.log(properties);
factoryBean.setJpaPropertyMap(properties);
factoryBean.afterPropertiesSet();

return factoryBean.getObject();

}


For debugging use this

   <!-- enable trace for binding -->
   <logger name="org.hibernate.jpa">
      <level value="debug" />
      <appender-ref ref="stdout" />

   </logger>

No comments:

Post a Comment