On the web, I found the following piece of code written within a Spring Data Configuration
class that connects to a data source:
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean userEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(userDataSource());
em.setPackagesToScan(
new String[] { "some.package" });
HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto",
env.getProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.dialect",
env.getProperty("hibernate.dialect"));
em.setJpaPropertyMap(properties);
return em;
}
What I noticed is that within this Spring configuration class there is no bean method that provides a hibernate SessionFactory, and instead Hibernate properties are passed as map as in the code above. Can SessionFactory bean method be omitted if I specify hibernate properties as in the code above? How will Sessions get created in that case? Which way should be preferred?
Thanks in advance!