Open
Description
Hi Team,
We have migrated our project to Spring Boot 3.2.5. As part of this migration, Spring Batch has also been updated. However, we are noticing that Spring Batch is failing with the driver "com.edb.Driver." I have set the databaseType to "POSTGRES," but it is still failing. I have tried using a custom CustomJobRepositoryFactoryBean, but the issue persists. Is there any workaround to fix this issue in version 5.1?
**Error**:
Caused by: java.lang.IllegalArgumentException: **DatabaseType not found for product name: [EnterpriseDB]**\n\tat org.springframework.batch.support.DatabaseType.fromProductName(DatabaseType.java:71)\n\tat org.springframework.batch.support.DatabaseType.fromMetaData(DatabaseType.java:109)\n\tat
Below is the workaround I tried.
@Bean
public JobRepository jobRepository(EntityManagerFactory entityManagerFactory) throws Exception {
log.info(
"Creating job repository instance------------------------------------------------------------------");
JobRepositoryFactoryBean fb = new JobRepositoryFactoryBean();
fb.setTransactionManager(transactionManager(entityManagerFactory));
fb.setIsolationLevelForCreate(ISOLATION_LEVEL);
fb.setTablePrefix("batch_schema.BATCH_");
try {
fb.setDatabaseType(DatabaseType.POSTGRES.name());
fb.afterPropertiesSet();
return fb.getObject();
} catch (Exception e) {
throw new BatchConfigurationException("Unable to configure the default job repo", e);
}
}
- Using CustomJobRepositoryFactoryBean
public class CustomJobRepositoryFactoryBean extends JobRepositoryFactoryBean {
@Override
public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource);
try {
String productName = dataSource.getConnection().getMetaData().getDatabaseProductName();
if ("EnterpriseDB".equalsIgnoreCase(productName)) {
super.setDatabaseType("POSTGRES"); //PostgreSQL
} else {
super.setDatabaseType(DatabaseType.fromProductName(productName).getProductName());
}
} catch (SQLException e) {
throw new RuntimeException("Failed to determine database type", e);
}
}
}