how to handle spring boot jpa batch execution failed transactions

南笙酒味 提交于 2019-12-12 06:48:06

问题


Having list which contains data model objects and passing it to saveALL method of CRUD repository. Using spring boot jpa batch concept to insert bulk data at a time. While bulk insert, spring jpa batch failed due to exceptions then all records are rollback. How to find correct and incorrect records? and we need to insert valid records into table without rollback and insert invalid records into error table. Please help me.

public void execeBatch() {

    try {
        if(!dataList.isEmpty()) {
            employeeRepository.saveAll(dataList);   
        }

    }catch(Exception e) {
        log.error("Exception while execeBatch..... and calling  handleBatchExceptions()");

        handleBatchExceptions();
    }
}
public void handleBatchExceptions() {

    for (EmployeeModel employeeModel : dataList) {
        try {

            employeeRepository.save(employeeModel);
        } catch (Exception e) {


        }
    }
    dataList.clear();

}

来源:https://stackoverflow.com/questions/58815646/how-to-handle-spring-boot-jpa-batch-execution-failed-transactions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!