I have this column. As I know, the time should be normalized to UTC in the database
{noformat}public class Purchase { @Id @GeneratedValue @GenericGenerator(name = "UUID", type = UuidGenerator.class) private UUID id;
@TimeZoneStorage(TimeZoneStorageType.TIMESTAMP_UTC) private ZonedDateTime purchasedAt; }{noformat}
Then, I try to save a record, where the time is created using {{ZonedDateTime}} with a non UTC {{ZoneId}} (the same as the local system).
{noformat}ZonedDateTime time = ZonedDateTime.of(2023, 6, 11, 15, 0, 0, 0, ZoneId.of("Asia/Jakarta"));
Purchase purchase = new Purchase(); puchase.setPurchasedAt(time);
Purchase savedPurchase = purchaseRepository.save(purchase);
Purchase retrievedPurchase = purchaseRepository.findById(savedPurchase.getId());{noformat}
The expected value should be {{2023-06-11 08:00:00}} (normalized to UTC), but I got {{2023-06-11 15:00:00}} in the database
I use PostgreSQL 12 and the column type is timestamp without timezone
Then, when the record is retrieved, the column value is {{2023-06-11T15:00Z}} which is incorrect.
I have seen the related code change in [https://github.com/hibernate/hibernate-orm/pull/4940/commits/7e4bacb1126bc6bf7a198d23f31859dd1f8feee8|https://github.com/hibernate/hibernate-orm/pull/4940/commits/7e4bacb1126bc6bf7a198d23f31859dd1f8feee8|smart-link]
But somehow the data stored in the database is incorrect
The value from hibernate log is {{binding parameter [2] as [TIMESTAMP_UTC] - [2023-06-11T08:00:00Z]}}
The parameter value from PostgreSQL log when inserting is {{$2 = '2023-06-11 15:00:00+07'}} (and stored in the database as {{2023-06-11 15:00:00}}) |
|