Spring Batch Structure - Create Package Table Automatically

I just created a batch job using the Spring Batch framework, but I don't have database privileges to run CREATE SQL. When I try to start a batch job, I find an error while the environment is trying to create TABLE_BATCH_INSTANCE. I'm trying to disconnect

<jdbc:initialize-database data-source="dataSource" enabled="false"> ... </jdbc:initialize-database> 

But after I tried, I still got the 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 

In any case, you can disable SQL, I just want to check if your reader and processor are working correctly.

+15
spring database spring-batch privileges ora-00942
source share
8 answers

The Spring Package uses the database to store metadata for its recovery / redo functions.

If you cannot create tables in the database, then you need to disable this behavior

If you can create batch metadata tables, but not at run time, you can create them manually

+8
source share

With Spring Boot 2.0, you probably need the following: https://docs.spring.io/spring-boot/docs/2.0.0.M7/reference/htmlsingle/#howto-initialize-a-spring-batch-database

 spring.batch.initialize-schema=always 

By default, it creates tables only if you use the built-in database.

Or

  spring.batch.initialize-schema=never 

To permanently disable it.

+13
source share

To enable the automatic creation of Spring data schema, simply add this line to the spring application.properties file:

spring.batch.initialize-scheme = always

To learn more about Spring's metadata schema, follow these steps:

https://docs.spring.io/spring-batch/trunk/reference/html/metaDataSchema.html

+2
source share

It seems stupid, but someone might have the same problem.

I was getting this error after deleting all the tables from the database. When I tried to start Spring Batch, I received an error message:

incorrect SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME of BATCH_JOB_INSTANCE, where JOB_NAME =? and JOB_KEY =?]

and:

Invalid object name 'BATCH_JOB_INSTANCE'

This happened to me because I delete tables without restarting the service . The service was started and received database metadata with package tables in the database. After deleting them and restarting the server, Spring Batch thought the tables still exist.

After restarting the Spring Batch server and restarting the package, the tables were created without errors.

+1
source share
Tag

<jdbc:initialize-database/> handled by Spring using InitializeDatabaseBeanDefinitionParser . You can try debugging this class in your IDE to make sure which values ​​are selected for the enabled attribute. You can also disable this value using the JVM parameter -Dspring.batch.initializer.enabled=false

0
source share
 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd"> <!-- database --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/springbatch" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> <!-- transaction manager --> <bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" /> <!-- create job-meta tables automatically --> <jdbc:initialize-database data-source="dataSource"> <jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql" /> <jdbc:script location="org/springframework/batch/core/schema-mysql.sql" /> </jdbc:initialize-database> </beans> 

And make sure you are using a compatible spring-jdbc version with spring-batch . Most likely spring -jdbc-3.2.2.RELEASE.JAR .

0
source share

this works for me: spring boot 2.0

  batch: initialize-schema: never initializer: enabled: false 
0
source share

When working with Spring Boot:

Running with Spring Boot v1.5.14.RELEASE, Spring v4.3.18.RELEASE

That should be enough:

 spring: batch: initializer: enabled: false 

The initialization scheme did not work for this boot version of Spring. After that, I was able to copy the SQL scripts from the spring-loaded jar and change the capital letter of the table, since this was my problem with automatically creating the table under Windows / Mac / Linux.

0
source share

All Articles