4

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

maryam
  • 147
  • 3
  • 11
  • `at the moment of the creation of the table no error was displayed.`. How are you creating the tables? – Mahmoud Ben Hassine Aug 16 '18 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 – maryam Aug 17 '18 at 08: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. – Mahmoud Ben Hassine Aug 17 '18 at 09:03

2 Answers2

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:

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • 1
    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 – Investigator Dec 21 '18 at 10:23
2

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 
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Mirza
  • 33
  • 5