Announcement Announcement Module
Collapse
No announcement yet.
Spring Job Restart Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Job Restart

    Hi,
    I was testing a Spring job restart logic.My sample code
    Code:
    <bean id="batchEmissionUpdateJob"
    		class="org.springframework.batch.core.job.SimpleJob">
    		 <property name="jobRepository" ref="jobRepository"/>
    		  <property name="restartable" value="true"> </property>
    		<property name="steps">
    			<list>
    				<ref bean="BatchEmissionUpdate" />
    				<ref bean="EmissiondeleteFile" />
    			</list>
    		</property>
    	</bean>
    
    	<bean id="BatchEmissionUpdate"
    		class="org.springframework.batch.core.step.item.SimpleStepFactoryBean">
    		<property name="transactionManager" ref="transactionManager" />
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="streams" ref="fileItemsReader" />
    		<property name="itemReader" ref="fileItemsReader" />
    		<property name="itemWriter" ref="emissionWriter" />
    		<property name="commitInterval" value="10000" />
    		<property name="allowStartIfComplete" value="false"></property>
    	</bean>
    First time It run successfully and when i try to run second time it is giving error as below
    Code:
    org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar 
    [SELECT JOB_INSTANCE_ID from JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; 
    nested exception is com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704,
     SQLERRMC: JOB_INSTANCE
    	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:276)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:607)
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:641)
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:670)
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:678)
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:710)
    	at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.getJobInstance(JdbcJobInstanceDao.java:189)
    	at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:155)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy2.createJobExecution(Unknown Source)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:79)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:205)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:252)
    Caused by: com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -204, SQLSTATE: 
    42704, SQLERRMC: JOB_INSTANCE
    I think this is due to allowStartIfComplete property i want to run the batch again.

    Please help me...
    Last edited by adish1234; May 14th, 2009, 11:57 AM.

  • #2
    Ignoring the stack trace for now, "allowStartIfComplete" is a property of the step, and the error seems to concern the JobInstance, so I would say it is unrelated.

    What do you mean exactly, when you say you "try to run second time"? You need to change the JobParameters if this is not a restart. (You said that the first execution was successful, so this is not a restart, right?)

    In any case I am not happy with the stack trace, so I'd like to understand better what you did and see if the error makes sense. The table name JOB_INSTANCE is not a standard one (did you change the table prefix in the JobRepository?). Does the table exist?

    Comment


    • #3
      Originally posted by Dave Syer View Post
      Ignoring the stack trace for now, "allowStartIfComplete" is a property of the step, and the error seems to concern the JobInstance, so I would say it is unrelated.

      What do you mean exactly, when you say you "try to run second time"? You need to change the JobParameters if this is not a restart. (You said that the first execution was successful, so this is not a restart, right?)

      In any case I am not happy with the stack trace, so I'd like to understand better what you did and see if the error makes sense. The table name JOB_INSTANCE is not a standard one (did you change the table prefix in the JobRepository?). Does the table exist?


      Thanks Dave for your reply.
      First time i executed the job successfully and i am trying the run the same job again with different parameter but it's not allowing me to run the job again .
      I have used
      <property name="restartable" value="true"> in the job
      and every step i have used
      <property name="allowStartIfComplete" value="false">
      and for every read and write i have used saveState = true

      Please let me know is it something blocking me to run the same job with different parameter.
      Thanks again...
      Last edited by adish1234; May 14th, 2009, 11:19 PM.

      Comment


      • #4
        The restartable and allowStartIfComplete flags have no bearing whatever on a fresh instance being launched. I want to understand the stack trace. You didn't answer the questions about the JobRepository. Does the table exist? Can you post the whole stack trace in case there is something useful there (all we have is a DB2 error code)?

        Comment


        • #5
          Originally posted by Dave Syer View Post
          The restartable and allowStartIfComplete flags have no bearing whatever on a fresh instance being launched. I want to understand the stack trace. You didn't answer the questions about the JobRepository. Does the table exist? Can you post the whole stack trace in case there is something useful there (all we have is a DB2 error code)?
          Dave,
          Thanks a lot for your reply.
          Yeah the table is exist in my Job Repository. All of my other jobs are working on the same Job repository.
          Attached the DB2 stack trace

          Comment


          • #6
            The second stack trace is different. It shows more clearly that there is a problem with your database: the table DGTR003.V_JOB_INSTANCE does not exist, or maybe your process does not have access or visibility to it. This is quite easy to work out from the stack trace and the DB2 documentation (although it would be nice if IBM would provide more friendly error messages).

            Comment

            Working...
            X