I am having an issue with executing a Job. I keep getting an IllegalArgumentException saying 'JobExecution must already be saved'.
- I have a MySQL DB set up and I used the DDL from schema-mysql.sql.
- My code snippet is listed below; as well as, my config files. I separated the setting up of the Batch framework with the definition of a Job.
- I also included the stack trace below.
I am sure I have some sort of configuration issue; but I can not figure out what it is. I followed another example (http://myartaud.free.fr/?p=66#test-our-case-1), but I can not figure out why it does not work.
Anyone know why this is not working?
Thanks in Advance
Code:private boolean runJob(String jobName) { try { Job job = getJobRegistry().getJob(jobName); getJobLauncher().run(job, new JobParameters()); return true; } catch (Exception e) { e.printStackTrace(); } return false; }HTML Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:batch="http://www.springframework.org/schema/batch" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- 1) USE ANNOTATIONS TO CONFIGURE SPRING BEANS <context:component-scan base-package="com.batch" /> --> <!-- 2) DATASOURCE, TRANSACTION MANAGER AND JDBC TEMPLATE --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/feed_sandbox" /> <property name="username" value="root" /> <property name="password" value="manager" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 3) JOB REPOSITORY - WE USE IN-MEMORY REPOSITORY FOR OUR EXAMPLE --> <bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"> <property name="transactionManager" ref="transactionManager" /> </bean> <!-- 4) LAUNCH JOBS FROM A REPOSITORY --> <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> </bean> <bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/> </beans>HTML Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:batch="http://www.springframework.org/schema/batch" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <import resource="classpath:/configuration/services/applicationContext.xml"/> <bean id="jobService" class="com.company.JobServiceImpl"> <property name="jobRegistry" ref="jobRegistry"/> <property name="jobLauncher" ref="jobLauncher"/> </bean> <bean id="HelloTask" class="com.company.PrintTasklet"> <property name="message" value="Hello"/> </bean> <bean id="SpaceTask" class="com.company.PrintTasklet"> <property name="message" value=" "/> </bean> <bean id="WorldTask" class="com.company.PrintTasklet"> <property name="message" value="World!"/> </bean> <batch:job id="HelloWorldJob" restartable="true"> <batch:step id="Hello" next="Space"> <batch:tasklet transaction-manager="transactionManager" ref="HelloTask"/> </batch:step> <batch:step id="Space" next="World"> <batch:tasklet transaction-manager="transactionManager" ref="SpaceTask"/> </batch:step> <batch:step id="World"> <batch:tasklet transaction-manager="transactionManager" ref="WorldTask"/> </batch:step> </batch:job> </beans>
Code:- Job: [FlowJob: [name=HelloWorldJob]] launched with the following parameters: [{}] - Encountered fatal error executing job java.lang.IllegalArgumentException: JobExecution must already be saved at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.batch.core.repository.dao.MapJobExecutionDao.updateJobExecution(MapJobExecutionDao.java:89) at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:151) .... ....


Reply With Quote