Uploaded image for project: 'JBeret'
  1. JBeret
  2. JBERET-29

Foreign key constraint step_execution_jobexecutionid_fkey fails when using Postgresql on WildFly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.0.0.Final
    • 1.0.0.CR2
    • jberet-core
    • None

      When starting a job using JobOperator.start(...), the executor throws the following exception:

      17:55:21,491 ERROR [org.jberet] (batch-batch - 1) JBERET000007: Failed to run job export, exportEntities, org.jberet.job.model.Step@683f4d77: javax.batch.operations.BatchRuntimeException: JBERET000626: Failed to run INSERT INTO STEP_EXECUTION(JOBEXECUTIONID, STEPNAME, STARTTIME, BATCHSTATUS) VALUES(?, ?, ?, ?)
      	at org.jberet.repository.JdbcRepository.insertStepExecution(JdbcRepository.java:585) [jberet-core-1.0.0.CR2.jar:1.0.0.CR2]
      	at org.jberet.repository.AbstractRepository.addStepExecution(AbstractRepository.java:181) [jberet-core-1.0.0.CR2.jar:1.0.0.CR2]
      	at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:112) [jberet-core-1.0.0.CR2.jar:1.0.0.CR2]
      	at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:162) [jberet-core-1.0.0.CR2.jar:1.0.0.CR2]
      	at org.jberet.runtime.runner.CompositeExecutionRunner.runFromHeadOrRestartPoint(CompositeExecutionRunner.java:88) [jberet-core-1.0.0.CR2.jar:1.0.0.CR2]
      	at org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:55) [jberet-core-1.0.0.CR2.jar:1.0.0.CR2]
      	at org.wildfly.jberet.services.BatchEnvironmentService$WildFlyBatchEnvironment$1.run(BatchEnvironmentService.java:149) [wildfly-jberet-8.0.0.Final-SNAPSHOT.jar:8.0.0.Final-SNAPSHOT]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_51]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_51]
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
      	at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
      	at org.jboss.threads.JBossThread.run(JBossThread.java:122)
      Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "step_execution" violates foreign key constraint "step_execution_jobexecutionid_fkey"
        Detail: Key (jobexecutionid)=(8) is not present in table "job_execution".
      	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
      	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
      	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
      	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
      	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
      	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363)
      	at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493)
      	at org.jberet.repository.JdbcRepository.insertStepExecution(JdbcRepository.java:579) [jberet-core-1.0.0.CR2.jar:1.0.0.CR2]
      	... 12 more
      

      The problem is that the job instance is created and inserted in the transaction that starts the job, while the execution is inserted in the transaction that belongs to the executor. Putting a breakpoint at BatchEnvironmentService:149 confirms this. If you wait long enough for the first transaction to complete, the job runs fine. JBeret should not start the job until the transaction is committed.

              jperkins-rhn James Perkins
              papegaaij Emond Papegaaij
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: