I have Spring Boot Data JPA
project running with UTC
timezone. This project communicates with MSSQL
database which runs with CST
timezone.
Now I understand that if I want to instruct spring boot project to consider database timezone, I have below 2 options.
- Change default TimeZone of
JVM
toCST
; which I do not want as I want to keep Spring boot application's timezone asUTC
only. - In
application.properties
file, set propertyspring.jpa.properties.hibernate.jdbc.time_zone=America/Chicago
so that hibernate can convert date fromUTC
toCST
whenever a record is inserted/updated/read from/to database.
Second option works great for me; however, I have a situation that underlying database could sooner be deployed on different datastore with another timezone. Hence I want to make the time zone property configurable (By configurable, I mean I will make this timezone as an environment variable, so that I no longer need spring boot
app reboot).
Is there any way to set the property spring.jpa.properties.hibernate.jdbc.time_zone
programmatically?