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

  • DataIntegrityViolationException

    hi,

    I am trying to run 2 simple jobs (2 "Hello World"-like steps each).
    I get the following exception:
    (cleaning batch tables does not help, the exception persists)
    I wonder what went wrong.
    Below is the exception and the job xml (the 2nd job is quite same except for the ids)

    the job
    Code:
    	<!-- 5) Beans representing the 2 job steps. -->
    	<!-- Step1 - print hello world -->
    	<bean id="helloTask" class="com.batch.simpletask.HelloTask">
    		<property name="taskStartMessage" value="Hello World - the time is now " />
    	</bean>
    	<!-- Step2 - print current time -->
    	<bean id="timeTask" class="com.batch.simpletask.TimeTask" />
    	
    	<bean id="sampleIncrementer" class="com.pursway.core.controller.test.SampleIncrementer"/>
    
    
    	<!-- 6) FINALLY OUR JOB DEFINITION. THIS IS A 2 STEP JOB -->
    	<batch:job id="simpleJob" restartable="true" incrementer="sampleIncrementer">
    		<batch:listeners>
    			<batch:listener ref="appJobExecutionListener" />
    		</batch:listeners>
    		<batch:step id="step1" next="step2">
    			<batch:tasklet ref="helloTask" />
    		</batch:step>
    		<batch:step id="step2">
    			<batch:tasklet ref="timeTask" />
    		</batch:step>
    	</batch:job>
    the exception
    Code:
    ERROR: org.springframework.batch.core.job.AbstractJob - Encountered fatal error executing job
    org.springframework.batch.core.JobExecutionException: Flow execution ended unexpectedly
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:105)
    	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
    	at org.springframework.batch.core.launch.support.SimpleJobOperator.startNextInstance(SimpleJobOperator.java:348)
    	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:597)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
    	at $Proxy10.startNextInstance(Unknown Source)
    	at com.pursway.core.controller.ExecutionController.run(ExecutionController.java:93)
    	at com.pursway.core.controller.ExecutionController.main(ExecutionController.java:54)
    Caused by: org.springframework.batch.core.job.flow.FlowExecutionException: Ended flow=simpleJob at state=simpleJob.step2 with exception
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:152)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:99)
    	... 14 more
    Caused by: org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT into BATCH_STEP_EXECUTION(STEP_EXECUTION_ID, VERSION, STEP_NAME, JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; Duplicate entry '0' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'PRIMARY'
    	at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.translate(SQLExceptionSubclassTranslator.java:69)
    	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:237)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:607)
    	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:792)
    	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:850)
    	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:854)
    	at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.saveStepExecution(JdbcStepExecutionDao.java:126)
    	at org.springframework.batch.core.repository.support.SimpleJobRepository.add(SimpleJobRepository.java:158)
    	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:597)
    	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 $Proxy9.add(Unknown Source)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:111)
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	... 16 more
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'PRIMARY'
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    	at com.mysql.jdbc.Util.getInstance(Util.java:381)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
    	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
    	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)
    	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)
    	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)
    	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    	at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:798)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:591)
    	... 36 more

  • #2
    found the problem

    after deleting tables content need to initialize sequence tables.

    Code:
    INSERT INTO BATCH_STEP_EXECUTION_SEQ values(0);
    INSERT INTO BATCH_JOB_EXECUTION_SEQ values(0);
    INSERT INTO BATCH_JOB_SEQ values(0);

    Comment

    Working...
    X