I'm using the spring batch to read data from Postgres DB. I've expireAt
column, which is of type Java.Instant
on the JPA side which should be lower than the current UTC time as per my query. I'm using hibernate's CURRENT_TIMESTAMP (with combination of spring.jpa.properties.hibernate.jdbc.time_zone=UTC
), but it's not providing current UTC time. I've also tried using now()
function but that too, depending on the client-side current timestamp. How should I get current UTC time in hibernate?
@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()
}
I thought to use Instant.now()
as the current UTC time, but I'm not able to pass that parameter to the job every time when it runs.