5

If the BATCH_JOB_EXECUTION_CONTEXT was not created all I get is :

Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO BATCH_JOB_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, JOB_EXECUTION_ID) VALUES(?, ?, ?)]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

the error above is displayed while inserting into the table, but at the moment of the creation of the table (done automatically by spring batch )no error was displayed.

I would like to know the reason way the table was not created so I could know what is the issue (database permissions, problems of tablespace...) is it possible to log it in traces?

for information I'm using oracle database 12C and ojdbc8 version 12.2.0.1

3
  • at the moment of the creation of the table no error was displayed.. How are you creating the tables? Commented Aug 16, 2018 at 20:27
  • I mean when spring batch wants to create the tables, because as far as I know spring batch create all 'table batch ' automatically when you run a project Commented Aug 17, 2018 at 8:17
  • Ok, this is where I wanted to come. Spring Batch assumes tables are already created in your datasource. You need to create them manually upfront or tell Spring Boot to create them for you using the spring.batch.initialize-schema property. See my answer for more details. Hope this helps. Commented Aug 17, 2018 at 9:03

4 Answers 4

6

Spring Batch does not automatically create meta-data tables in your datasource. You need to run the tables creation script against your database manually.

However, if you use Spring Boot, those tables can be created automatically using the spring.batch.initialize-schema property. More details here: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-initialize-a-spring-batch-database

There are similar/related questions to this one, I'm adding them for reference here:

Sign up to request clarification or add additional context in comments.

1 Comment

If you use Spring Boot the variable that you must use depends on the version. For example with Spring Boot v1.5.14.RELEASE, Spring v4.3.18.RELEASE you should use: spring.batch.initializer.enabled=false
3

Check your Spring Boot starter class or configuration class and make sure you are not excluding this auto configuration:

(exclude={BatchAutoConfiguration.class})

Also make sure this property is not set to never:

spring.batch.initialize-schema 

Comments

3

spring.batch.initialize-schema is deprecated and instead of using it use:

spring.batch.jdbc.initialize-schema=always

1 Comment

For me it does not work in the first run, but when i rerun the application after getting the error, it does creates. Is there a fix for this issue?
1

I recently faced this issue with spring.batch.jdbc.initialize-schema populated to always and no presence of @EnableBatchProcessing (Spring Boot 3, Spring Batch 5). The tables were still not created.

Turns out that the database user we had in cluster did not have CREATE TABLE permission. And the creation step was failing silently. I could identify this by enabling DEBUG logs for org.springframework.jdbc.datasource.init.ScriptUtils class.

This was the error logged that helped in resolving the issue:

{"@timestamp":"...","@version":"1","message":"Failed to execute SQL script statement #4 of class path resource [org/springframework/batch/core/schema-sqlserver.sql]: CREATE TABLE BATCH_STEP_EXECUTION ...","logger_name":"org.springframework.jdbc.datasource.init.ScriptUtils","thread_name":"main","level":"DEBUG","level_value":10000,"stack_trace":"com.microsoft.sqlserver.jdbc.SQLServerException: CREATE TABLE permission denied in database 'test'

Based on this error, the resolution for my case was just to grant the CREATE TABLE permission to the database user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.