postgresql - 在春季批处理中获取 HQL 查询中的 UTC 时间
问题描述
我正在使用 spring 批处理从 Postgres DB 中读取数据。我有一个expireAt
列,它是Java.Instant
JPA 端的类型,根据我的查询,它应该低于当前的 UTC 时间。我正在使用休眠的 CURRENT_TIMESTAMP(与 的组合spring.jpa.properties.hibernate.jdbc.time_zone=UTC
),但它不提供当前的 UTC 时间。我也尝试过使用now()
函数,但这也取决于客户端当前的时间戳。我应该如何在休眠状态下获取当前的 UTC 时间?
@Bean
fun postgresPostReader(): ItemReader<Post> {
return JpaPagingItemReaderBuilder<Post>()
.name("postgresPostReader")
.entityManagerFactory(entityManagerFactory)
.queryString("SELECT p FROM Post p WHERE p.expireAt <= CURRENT_TIMESTAMP")
.pageSize(1000)
.build()
}
我想Instant.now()
用作当前的 UTC 时间,但是每次运行时我都无法将该参数传递给作业。
解决方案
推荐阅读
- c - 带链表 C 的冒泡排序
- android - 不同会话中 PWA 的可信 Web 活动
- docker - 可以将文件夹挂载到docker容器的根目录中吗
- python - 如何检查 Python/HTML 表单中的重复用户输入?
- ios - Fastlane iOS 自动通知截图
- java - 拆分器中的 action.accept(val) 做什么
- python - 使用 ODEINT 或其他方法求解许多耦合微分方程组
- javascript - 简单的函数在使用 onclick 时触发,在 JS 中使用 addEventListener 时不会触发
- nginx - 每次添加第二个虚拟主机后,NGINX 重启都会失败
- node.js - Mongo Aggregate - 获取查询结果中出现多个值的次数