I\'m trying to set up spring xml configuration without having to create a futher persistence.xml
. But I\'m constantly getting the following exception, even thou
MariuszS' answer is good except that the entityManagerFactory
method should return EntityManagerFactory. To do that it can be written like this:
@Bean
public EntityManagerFactory entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setPackagesToScan("hello");
return lef.object();
}
For future audience: below code worked:
@Bean (name = "entityManagerFactory")
public EntityManagerFactory entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter)
{
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setPackagesToScan("*.models*");
lef.afterPropertiesSet(); // It will initialize EntityManagerFactory object otherwise below will return null
return lef.getObject();
}