Setup:
Hibernate: 5.4.32
SpringBoot: 2.5.4
org.postgresql:postgresql: 42.2.23
I have a class and table
@Entity
public class MyType{
@Id
@GeneratedValue(generator = "uuid2")
@Type(type = "uuid-char")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
private UUID id;
@Column
public ZonedDateTime time;
public MyType(){}
// omitting getters and setters
}
create table if not exists my_type
(
id text not null
constraint idx_16559_pk__data_fil__3213e83ff1283b3a
primary key,
time timestamp with time zone
)
Problem
What I want to achieve is to preserve the timezone information in MyType.time when writing to the database.
No matter what I try it is always converted to UTC. There is an option (hibernate.jdbc.time_zone) to set a specific timezone but I want to persist ZonedDateTime instances with different timezones and since Java and Postgres have a type for this I would expect some way to achieve this.
Worst case scenario for me would be to just store it as a string and do de-/serialization manually.