spring boot + jpa 实现 sql 更新表数据

注意要在类上增加注解:@Transactional,否则会报异常:

Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query

例子:

@Transactional //注意增加这个
public interface BeanDao extends JpaRepository {

    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,
            value = " update temp set user = 'admin', state='FAIL', remark='step fail , process end' where current_step > :currentStep and record_id= :recordId   ")
    void setOtherStepFail(@Param("currentStep") Integer currentStep, @Param("recordId") Long recordId);

}

你可能感兴趣的:(Java,spring,boot,sql,java)