spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

DatabaseType EnterpriseDb not found in spring batch 5.1

Open chetan1993-prog opened this issue 1 year ago • 4 comments

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("users_owner.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);
    }
  }
  1. 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);
    }
  }
}

chetan1993-prog avatar Oct 14 '24 09:10 chetan1993-prog