Home > other >  why mysql and hibernate return incorrect date in the code(-1 day at 18:00:00)
why mysql and hibernate return incorrect date in the code(-1 day at 18:00:00)

Time:01-26

I have a little problem with mysql hibernate. in the database I have: records from DB

I don't have any record of January 13th 2023

if I perform a query to get this information of the January 14th 2023, in the code I get this:

date in the code

I don't know why if in the database I have 14-jan-23 in the code I get: 13-jan-23 18:00:00

I thing that it's a configuration problem, in the hibernate.cfg.xml I have:

<property name="connection.url">jdbc:mysql://localhost:3306/metsa?serverTimezone=UTC</property>

any one knows what I have wrong?

I tried to change the time zone in mysql, but doesn't matter what I set, always I have the same date in the code -1 day at 18:00:00

SET @@global.time_zone = ' 00:00';
SET @@session.time_zone = ' 00:00';

CodePudding user response:

I solved this adding this in the date field:

@Temporal(TemporalType.DATE)

  • Related