Search code examples
postgresqlhibernatespring-data-jpahibernate-criteria

Spring JPA with criteria builder convert timestamp with timezone to local time with given time zone


I am using PostgreSQL as db, i have a timestamptz column I want to convert it into given timezone.

select 
  shipment0_.estimated_delivery_date_time at time zone 'IST'
from 
  shipment shipment0_

is the query, How can I implement it using JPA criteria with timezone as a user input. I cannot use native query or JPQL since I already have other filters using criteria API


Solution

  • As per this blog post https://vladmihalcea.com/sql-functions-multiple-parameters-jpql-hibernate/

    Managed to register a custom function using MetadataBuilderContributor