我将时间戳与
now = LocalDateTime.now()
与本机查询和 update
一起使用,后来我使用与数据库中的 now
相同的 select
变量。微软SQL。我正在使用这个 Java Spring Boot。在存储库中。我希望这是足够的解释和代码,否则我可以尝试做更多描述。谢谢您提供的所有信息。
@Modifying
@Transactional
@Query(value = "UPDATE xy SET ts = :timestamp", nativeQuery = true)
void update(LocalDateTime timestamp);
@Query(value = "SELECT * FROM xy WHERE ts = :timestamp", nativeQuery = true)
List<List<String>> select(LocalDateTime timestamp);
// and then I call
LocalDateTime now = LocalDateTime.now();
update(now);
list = select(now);
// and the list is empty
使用
@Modifying
注释会使持久化上下文过时,要解决这个问题,您可以指定一个属性 -
@Modifying(clearAutomatically = true)
确保 PC 从数据库中获取实体。