I am migrating my application from Spring Boot 1.5 to 2 (and hopefully from Tomcat to Hikari in the process). I've solved all the compilation errors, but now I'm getting this error (I've removed most of the stacktrace as I see no important info on it):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pexEntityManagerFactory' defined in class path resource [com/xisumavoid/gateway/db/PexDbConfig.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
[...]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
I have 2 classes that act as database configuration, as my application has to access 2 databases (Named 'primary' and 'pex'). The PexDbConfig
looks like this:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "pexEntityManagerFactory",
transactionManagerRef = "pexTransactionManager",
basePackages = { "com.xisumavoid.gateway.db.pex.repositories" }
)
public class PexDbConfig {
@Bean(name = "pexDataSource")
@ConfigurationProperties(prefix = "pex.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "pexEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean pexEntityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("pexDataSource") DataSource dataSource
) {
return builder
.dataSource(dataSource)
.packages("com.xisumavoid.gateway.db.pex.models")
.persistenceUnit("pex")
.build();
}
@Bean(name = "pexTransactionManager")
public PlatformTransactionManager pexTransactionManager(
@Qualifier("pexEntityManagerFactory") EntityManagerFactory
pexEntityManagerFactory
) {
return new JpaTransactionManager(pexEntityManagerFactory);
}
}
Sorry for the messy code, long class names are hard to deal with. Also, in case it's needed, here's the relevant config section:
## DB - PRIMARY
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/primary
spring.datasource.username=user
spring.datasource.password=password
## DB - PEX
pex.datasource.driver-class-name=com.mysql.jdbc.Driver
pex.datasource.url=jdbc:mysql://localhost:3306/pex
pex.datasource.username=user
pex.datasource.password=password
How do I fix this, or even better yet, is there a way to do this in a simpler way?
Thanks in advance!