Quartz: add transaction rollback error [How to Solve]

automatic task class:

public class ReCodeBack implements Job {

    private static final Logger LOGGER = LoggerFactory.getLogger(ReCodeBack.class);

    ReCodeBackTag reCodeBackTag;

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {


Automatic task annotation:



task requirements are transactions that need to be added

use spring annotation @ transactional annotation

     * Adding (deleting) table data
     * @param object
     * @param modular
     * @return
    @Transactional(rollbackFor = Exception.class)
    public int tableOperation (Object object,String modular){
    int count = 0;
    }catch (Exception e) {
            LOGGER.info("[Add (delete) table data] ERROR : {}", e.getMessage());
            //transaction rollback
            //Task is abnormally interrupted and immediately re-run
            JobExecutionException e2 = new JobExecutionException(e);
            throw e2;
        }finally {
            return count;

Note: when the author uses @transactional annotation in the automatic task class, the program will report an error (too lazy… The reason is not clear, and it will be supplemented later). Therefore, the author is divided into two classes to write, one-timing call class and one business class, as shown in the above code

Similar Posts: