Home > database >  Error: Method threw 'org.springframework.dao.InvalidDataAccessResourceUsageException' exce
Error: Method threw 'org.springframework.dao.InvalidDataAccessResourceUsageException' exce

Time:03-31

I am trying to update the data , but it is giving me the exception , i don't know what should i do cause i tried so many methods even adding the @Transactional -

 @RequestMapping(value = "/make-zero",method = RequestMethod.GET)
    public String home(Model model ) {
        try {
            int x = employeeEventRepository.setToZero();
            System.out.println("login is: "   x);
            model.addAttribute("login", x);
        }
        catch (Exception e){
            System.out.println(e);
                    }
        return "redirect:/timetracking/compensatory/pereschet";

    }

and this is my SQL method

 @Transactional
    @Query(value = "update TT_EMPLOYEE_EVENT set status = 0  where is_approved = 1 and status = 1 and create_date < current_timestamp - numtodsinterval(30, 'minute');COMMIT ;",nativeQuery = true)
    int setToZero();

Maybe update query is not giving me int type ?

CodePudding user response:

Put @Modifying annotation on top of the @Query annotation

Because @Modifying annotation enhances the @Query annotation to execute INSERT, UPDATE, DELETE, and DDL queries

  • Related