use of org.springframework.orm.hibernate5.LocalSessionFactoryBean in project midpoint by Evolveum.
the class TestSqlRepositoryBeanConfig method sessionFactory.
/*
* This is working alternative to @Autowired private LocalSessionFactoryBean sessionFactory
* with @PostConstruct init method that adds the properties. That solution didn't work, because
* the properties are probably used to initialize the session before added.
* This nicely reuses existing production config method and adds the properties before they
* are read and reflected in the final setup.
* (There is actually just one test that using the inspector - ObjectDeltaUpdaterTest.)
*/
@Bean
@Primary
public LocalSessionFactoryBean sessionFactory(DataSource dataSource, SqlRepositoryConfiguration configuration, MidPointImplicitNamingStrategy midPointImplicitNamingStrategy, MidPointPhysicalNamingStrategy midPointPhysicalNamingStrategy, EntityStateInterceptor entityStateInterceptor) {
LocalSessionFactoryBean sessionFactory = new SqlRepositoryBeanConfig().sessionFactory(dataSource, configuration, midPointImplicitNamingStrategy, midPointPhysicalNamingStrategy, entityStateInterceptor);
// These are only test-related changes regarding the session factory.
Properties hibernateProperties = sessionFactory.getHibernateProperties();
hibernateProperties.setProperty("hibernate.show_sql", "false");
hibernateProperties.setProperty("hibernate.session_factory.statement_inspector", "com.evolveum.midpoint.repo.sql.testing.TestStatementInspector");
return sessionFactory;
}
Aggregations