martinweiler opened a new issue, #7308: URL: https://github.com/apache/incubator-kie/issues/7308
**Problem** After restarting a Quarkus app that uses embedded jobs with JPA/PostgreSQL, overdue timers fire as expected. Some of the job-timeout transactions then fail at commit with: ``` ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed ... jakarta.persistence.OptimisticLockException: Unexpected row count (expected row count 1 but was 0) [update job_details set correlation_id=?, ... where id=?] for entity [org.kie.kogito.app.jobs.jpa.model.JobDetailsEntity with id '...'] Caused by: org.hibernate.StaleObjectStateException ``` The error does not appear when timers fire while the app is running. **Reproduction** 1. Start 100 instances of a process with an intermediate timer (`delay = PT2M`) and a script task that sleeps 10 s after the timer, using PostgreSQL persistence. 2. Stop the Quarkus app, leaving PostgreSQL running, and wait more than 2 minutes. 3. Start the app again. The timers fire and the exception is logged. **Root cause** - `JobDetailsEntityHelper.from()` removed `classType` from `instance.getRecipient()` and `instance.getTrigger()`. These are the managed entity's own `ObjectNode` attributes. - `VertxJobScheduler.syncWithJobStores()` loads jobs through `JPAJobStore.loadActiveJobs()`, which calls `from()`. The JSON mutation made Hibernate treat every loaded job as dirty. At commit it issued an `UPDATE job_details` for each of them. `JobDetailsEntity` has no `@Version`, so the `UPDATE` matches on id only. - After a restart, the jobs are overdue and their timers fire after 1 ms. Their timeout transaction takes the row lock through `shouldRun()` (`UPDATE ... SET status='RUNNING'`) and later deletes the row. The sync transaction's `UPDATE` waits for the lock, then matches 0 rows, so Hibernate throws `StaleObjectStateException`. - Beyond the log noise, the stale `UPDATE` writes all columns. If it lands before the delete, it could overwrite `RUNNING` with `SCHEDULED`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
