/** This transaction will be marked for rollback. A command will be associated with the
* Transaction.EVENT_AFTERCOMPLETION (after the job locks of the current transaction are
* released). Then the command will update the job with the exception details in a separate
* transaction. */
protected void handleJobExecutionException(Environment environment, JobImpl<?> job, Exception exception) {
Transaction transaction = environment.get(Transaction.class);
CommandService commandService = (CommandService) environment.get(CommandService.NAME_NEW_TX_REQUIRED_COMMAND_SERVICE);
JobExceptionHandler jobExceptionHandler = new JobExceptionHandler(job.getDbid(), exception, commandService);
transaction.registerSynchronization(jobExceptionHandler);
if (exception instanceof RuntimeException) {
throw (RuntimeException) exception;
}
throw new JbpmException("job failed: "+exception.getMessage(), exception);