简体   繁体   中英

Hibernate DST Date mapping issue for timestamps without time zone

I've a problem with storing java.util/sql.Date in PostgreSQL using hibernate: I'm storing dates as timestamp without time zone type. Now, in most cases everything is alright, as I'm mapping it in entities as java.util(sql).Date .

However, I encountered one problem I don't know how to overcome yet: On March 30th there was a time change ( Daylight Saving Time started). In my country it meant switching from local 2am to local 3am .

In my database I have few entries with times between 2 and 3 am, such as

"2014-03-30 02:15:55"

Now, what Java does is it takes this date and displays it as 3:15:55 am, because of the time change. However, I desperately need it to be 02:15:55, exactly how it's stored in the database (basically meaning don't use the +02:00 timezone BEFORE 3am, but use it AFTER ). I'm afraid about 26th October as well, that's when the DST ends.

Is this possible using Hibernate and/or Spring? I'd love a global config for such case.

Best, Marcin

You need to store dates in UTC timezone to ignore DST. See this question How to store date/time and timestamps in UTC time zone with JPA and Hibernate for solutions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM