1

I have a problem when I add table-prefix in the application properties, Spring-Batch doesn't get the property and sets the default prefix BATCH_.

spring.batch.table-prefix=SOMETHING.BATCH_

Spring Version

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
</parent>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.0.4.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
</dependency>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
        <version>2.1.2.RELEASE</version>
 </dependency>

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

Vega
  • 27,856
  • 27
  • 95
  • 103
  • Possible duplicate of [Spring batch tables in a different schema](https://stackoverflow.com/questions/47039596/spring-batch-tables-in-a-different-schema) – Mahmoud Ben Hassine Jul 17 '19 at 07:33
  • Possible duplicate of https://stackoverflow.com/questions/37436658/spring-batch-table-prefix-when-using-java-config – Mahmoud Ben Hassine Jul 17 '19 at 07:34
  • I provided two links to similar questions. This should help. If it is not the case, please share a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and I will try to help you. – Mahmoud Ben Hassine Jul 17 '19 at 07:38

1 Answers1

0

I solved the problem and it's working fine.

I injected a new JobRepository created with a JobRepositoryFactoryBean. In JobRepositoryFactoryBean, I have configured the data source and prefix, with this when jobs start the JdbcJobInstanceDao has the prefix.

I share the solution:

       private PlatformTransactionManager transactionManager(){
          return new ResourcelessTransactionManager();
        }
      private JobRepository createJobRepository() throws Exception {
         JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
         factory.setDataSource(dataSourceAudit);
         factory.setTransactionManager(transactionManager());
         factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
         factory.setTablePrefix("SOMETHING.BATCH_");
         factory.setDatabaseType("ORACLE");
         factory.setMaxVarCharLength(1000);
          return factory.getObject();
      }

      @Bean
        public JobLauncher jobLauncherBc() throws Exception{
             SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
             jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
             jobLauncher.setJobRepository(createJobRepository());
            return jobLauncher;
    }