0

I am writting Spring boot application for Spring batch, where ItemReader reads the data from Oracle Database and writes the data into postgres sql , but i am getting the below error

Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by JOB_INSTANCE_ID desc]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "batch_job_instance" does not exist
  Position: 39
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:234) ~[spring-jdbc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402) ~[spring-jdbc-5.0.8.RELEASE.jar:5.0.8.RELEASE]

I dont want to create the spring batch metadata table , my application not need for monitoring the jobs, please suggest me on this. Thanks in advance!!

Pandit Biradar
  • 1,777
  • 3
  • 20
  • 35

2 Answers2

2

According to your exception, it looks like Spring Batch is configured to use the Postgres data source for its metadata and it does not find the BATCH_JOB_INSTANCE table.

If you don't want to use meta-data tables, you can:

Then you can configure an Oracle datasource for your reader and a Postgres datasource for your writer.

Nothing prevents from having multiple datasources in your Spring Batch app, you just need to configure which one to use for your business logic and which one to be used by Spring Batch for its internal mechanics.

There are similar questions that might help, I'm adding them here for reference:

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • Thanks!! for the deatiles explanation as of now i am keeping batch metadata in postgres. – Pandit Biradar Aug 12 '18 at 14:49
  • @Mahmoud - Could you please guide here: https://stackoverflow.com/questions/59544730/spring-batch-how-to-create-metadata-tables-on-different-schema/59544931#59544931 – PAA Dec 31 '19 at 15:11
1

Use Below properties

spring.batch.initialize-schema=always or never

or else you can create the tables in ur DB. You can also find the schema for respective dbs in below jar.
Spring-batch-core.jar in maven dependencies if you are using maven. in classpath:/org/springframework/batch/core/

vvardhanz
  • 657
  • 1
  • 4
  • 7