I am trying to obtain Hibernate SessionFactory. I was unsuccessful so far.
I am using Java Config (no XML files) and Annotations.
My persistence config is the following:
I am tring to @Inject SessionFactory in my repository object but I am getting:
Failed to load ApplicationContext.
Do you have any way to extract SessionFactory from this environment?
I am using Java Config (no XML files) and Annotations.
My persistence config is the following:
Code:
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
log.info("Scanning the following packages for JPA entities: ");
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(ds);
emf.setPackagesToScan("com.msi.nsi.cmm.jpa");
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabase(Database.MYSQL);
adapter.setShowSql(true);
Properties jpaProperties = new Properties();
jpaProperties.setProperty("hibernate.format_sql", "true");
jpaProperties.setProperty("hibernate.dialect",
"org.hibernate.dialect.MySQLDialect");
jpaProperties.setProperty("hibernate.cache.provider_class",
"org.hibernate.cache.SingletonEhCacheProvider");
jpaProperties.setProperty("hibernate.cache.provider_configuration",
"/com/msi/nsi/cmm/framework/ehcache-cmm.xml");
jpaProperties.setProperty("hibernate.cache.use_second_level_cache",
"true");
jpaProperties.setProperty("hibernate.cache.use_query_cache", "true");
jpaProperties.setProperty("hibernate.cache.region.factory_class",
"org.hibernate.cache.ehcache.EhCacheRegionFactory");
emf.setJpaVendorAdapter(adapter);
emf.setJpaProperties(jpaProperties);
return emf;
}
Failed to load ApplicationContext.
Do you have any way to extract SessionFactory from this environment?