Reputation: 87
I doing annotation based coding, I am trying to run the application with Spring, Hibernate configuration and it is failing with error
Caused by: java.lang.IllegalArgumentException: No PersistenceProvider
specified in EntityManagerFactory configuration, and chosen
PersistenceUnitInfo does not specify a provider class name either
Below is my code
@SpringBootApplication
@EnableJpaRepositories
public class CurrExDemoApplication {
public static void main(String[] args) {
SpringApplication.run(CurrExDemoApplication.class, args);
}
@Bean
@ConfigurationProperties("app.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan("com.currencyExchange.currExDemo");
Properties props = new Properties();
props.put("showSql", true);
props.put("databasePlatform", Database.MYSQL);
props.put("hibernate.hbm2ddl.auto", "create");
em.setJpaProperties(props);
return em;
}
}
What is wrong in this code?
Upvotes: 1
Views: 3398
Reputation: 4451
Seems like you are missing at least the JpaVendorAdapter
add it like this:
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabasePlatform(hibernateDialect);
emf.setJpaVendorAdapter(vendorAdapter);
hibernateDialect is e.g. org.hibernate.dialect.MySQL5Dialect
but that depends on your database.
Upvotes: 2