首页 > 解决方案 > 在春季批处理中获取 HQL 查询中的 UTC 时间

问题描述

我正在使用 spring 批处理从 Postgres DB 中读取数据。我有一个expireAt列,它是Java.InstantJPA 端的类型,根据我的查询,它应该低于当前的 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 时间,但是每次运行时我都无法将该参数传递给作业。

标签: postgresqlspring-boothibernatespring-data-jpaspring-batch

解决方案


推荐阅读