【问题标题】:Why MySQL View return old data after I execute update query on my table data in Spring Boot?为什么我在 Spring Boot 中对表数据执行更新查询后 MySQL View 返回旧数据?
【发布时间】:2021-05-25 04:56:33
【问题描述】:

我有一个表,一个视图依赖于表。运行更新查询后,表数据成功更新,但通过以下语句,我从 View 中获取数据,这给了我旧数据。

this.userRepository.save(userData.get());

Optional<UserView> userView = this.userViewRepository.findById(userId);
        
return CompletableFuture.completedFuture(new ResponseEntity<>(userView.get(), HttpStatus.OK));

userData.get() 已更新数据。和 View 的数据存储在 userView 对象中,其中包含旧数据。

下面是调试查询输出,它显示 View 的查询首先运行,然后更新查询更新数据。有什么建议吗?

【问题讨论】:

    标签: mysql spring spring-boot view spring-data-jpa


    【解决方案1】:

    我唯一能想到的就是查询缓存。你可以试试:

    RESET QUERY CACHE
    

    如果你没有使用查询缓存,你可以试试:

    FLUSH TABLE
    or
    FLUSH TABLE <table_name>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-19
      • 2018-09-19
      • 2020-01-13
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      相关资源
      最近更新 更多