I am autowiring service in controller. And in service, I have a scenario where I need to throw an exception and DB changes also. So, I tried @Async
@Transactional
public void verifyOtp(OtpDto otpDto)
   ...
   if(xyz){
       deactivateOtp(emp.getId());
       throw new ServException("Mobile no requested is already assigned", "error-code");
   }
}
@Async
@Transactional //with or without
public void deactivateOtp(Integer id){
     otpRepo.deactivateOtp(id);
}
public interface OtpRepository extends JpaRepository<Otp, Integer> {
    @Modifying
    @Query("UPDATE Otp SET isActive = 0 WHERE id = :id")
public void deactiveOtp(@Param("id") Integer id);
This is not creating new thread. But, if I gives at repo, it works
public void deactivateOtp(Integer id){
     otpRepo.deactivateOtp(id);
}
public interface OtpRepository extends JpaRepository<Otp, Integer> {
    @Async
    @Transactional
    @Modifying
    @Query("UPDATE Otp SET isActive = 0 WHERE id = :id")
public void deactiveOtp(@Param("id") Integer id);
 
     
    