spring-batch

No Exception when Spring batch tables are not created


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


Solution

  • 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: