I am getting above error
Getting java.lang.NullPointerException: Cannot invoke "org.hibernate.boot.spi.MetadataImplementor.getEntityBindings()" because "this.metadata" is null
when I am configuring JPA EntityManagerFactory pro-grammatically using Spring JPA in a Spring MVC project. This is being thrown when I am booting the Tomcat.
Here is the specific code related to
@Configuration
@Bean
public DataSource dataSource() {
try {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
Class<? extends Driver> driver = (Class<? extends Driver>) Class.forName("org.h2.Driver");
dataSource.setDriverClass(driver);
dataSource.setUrl("jdbc:h2:mem:test");
dataSource.setUsername("SA");
dataSource.setPassword("");
return dataSource;
} catch (Exception e) {
System.out.println( e );
logger.error("Embedded DataSource bean cannot be created!", e);
return null;
}
}
@Bean
public Properties hibernateProperties() {
Properties hibernateProp = new Properties();
hibernateProp.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
hibernateProp.put("hibernate.hbm2ddl.auto", "create-drop");
hibernateProp.put("hibernate.show_sql", true);
hibernateProp.put("hibernate.max_fetch_depth", 3);
hibernateProp.put("hibernate.jdbc.batch_size", 10);
hibernateProp.put("hibernate.jdbc.fetch_size", 50);
return hibernateProp;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager(entityManagerFactory());
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
return vendorAdapter;
}
@Bean
public EntityManagerFactory entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setPackagesToScan("com.apress.prospring5.ch16.entities");
factoryBean.setDataSource(dataSource());
factoryBean.setJpaProperties(hibernateProperties());
factoryBean.setJpaVendorAdapter(jpaVendorAdapter());
factoryBean.afterPropertiesSet();
return factoryBean.getNativeEntityManagerFactory();
}
}
Tried various configuration with DataSource.