Spring-batch doesn't get the property spring.batch.table-prefix
See original GitHub issueHi everybody, 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_.
Any Idea ?
Error 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
Property 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>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Spring-batch doesn't get the property spring.batch.table-prefix
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_ ......
Read more >Spring Batch - Reference Documentation
Allocate enough memory at the beginning of a batch application to avoid ... Another modifiable property of the JobRepository is the table prefix...
Read more >Create Spring Batch metadata table on different schema
In this example, I've created Spring Batch metadata tables on same MySQL host but on different schema altogether. "test" schema will have ......
Read more >Spring batch using mysql SQLSyntaxErrorException table ...
batch.jdbc.table-prefix=batch in my properties file. When spring batch creates it's tables, it added batch_tablename E.G, BATCH_JOB_EXECUTION_CONTEXT. but when ...
Read more >Spring Batch metadata tables are not created automatically?
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"> ; <property name=" ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@snicoll I´m sorry, I can’t share source code because it’s for a business job.
I need to connect to the database (Oracle) with a specific schema, for this I add the property in the application.properties, spring.batch.table-prefix=SOMETHING.BATCH_ , but when Spring run the query -> SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ? , throws an exception because it does not find the table BATCH_JOB_INSTANCE. [ORA-00942: table or view does not exist]
This is because the tables are in another schema and Spring gets tablePrefix as BATCH_ (default) and not as SOMETHING.BATCH_, so when Spring concatenates the prefix, the result is BATCH_JOB_INSTANCE and not SOMETHING.BATCH_JOB_INSTANCE.
Thank you very much!
Reason for this error : Spring Boot / Spring Batch needs default tables where it can track the batch job related information. If the tables are not available in the database, we need to allow Spring to create them. To configure this please add the following line in application.properties.
spring.batch.initialize-schema=always
If this doesn’t work, you can manually create tables by running the following script. See this: https://poopcode.com/bad_sql_grammar_batch_job_instance/