Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1059869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:14:20+00:00 2026-05-16T18:14:20+00:00

I have a wierd hibernate related issue while setting a date field in an

  • 0

I have a wierd hibernate related issue while setting a date field in an entity.
The date is interpreted as UTC in the java program (i did a System.out to make sure the date assigned is in ‘UTC’. However, when hibernate actually persists to the database, the date is converted to local time and stored)
ex. the value has been set in the entity setter as “2009-09-09 00:08:08” – GMT
the actual value persisted to the database is “2009-09-08 08:08:08” – eastern time US.
I am unable to find out where and why this is happening and how to prevent it. Thanks

P.S. I am using joda date library and annotate the field with
@org.hibernate.annotations.Type(type = “org.joda.time.contrib.hibernate.PersistentDateTime”)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:14:21+00:00Added an answer on May 16, 2026 at 6:14 pm

    However, when hibernate actually persists to the database, the date is converted to local time and stored) ex. the value has been set in the entity setter as "2009-09-09 00:08:08" – GMT the actual value persisted to the database is "2009-09-08 08:08:08" – eastern time US.

    Ok, first, whatever column type are you using to store your date in MySQL (TIMESTAMP or DATETIME), neither stores the time zone. From Re: Storing timezone with datetime:

    • TIMESTAMP is seconds since 1970, sitting in 4 bytes. It is stored in GMT. That is, the TZ offset is applied as you store a value, then reapplied when you fetch it. (…)

    • DATETIME is an 8-byte string of digits "yyyymmddhhmmss". (…)

    And second, unless a buggy behavior, my understanding is that the conversion is supposed be done either by the server or by the JDBC driver depending on the the server time zone settings so that you don’t get inconsistent data.

    In both cases, my point is that storing "2009-09-09 00:08:08" – GMT or "2009-09-08 08:08:08" – eastern time US from Java should yield to the same value in the database.

    However, it looks like a different conversion is done when displaying them. This begs the question: how did you actually check the value of the "persisted date". Does the "problem" occur in your SQL client? In Java code?

    References

    • 9.6. MySQL Server Time Zone Support
    • 21.3.4.1. Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J
    • Bug #15604: TimeZone discarded storing java.util.Calendar into DATETIME

    MySQL documentation for DateTime says "MySQL retrieves and displays DATETIME values in ‘YYYY-MM-DD HH:MM:SS’ format". That means mysql converts the ‘milliseconds since epoch’ to the above format. So now my question becomes, is timezone info also stored in mysql?

    I’ve updated my initial answer (which was not totally accurate/exhaustive). Whether you’re using DATETIME or TIMESTAMP, the answer is no.

    Another observation I made is, the above date ‘conversion’ issue exists only when Im setting the date in the Java application. If I create a mysql trigger to update/set date using ‘UTC_TIMESTAMP()’, the date is displayed in the ‘UTC’ time.

    The UTC_TIMESTAMP() function always returns the current UTC date and time.


    What I’d like to know is:

    • How did you "reveal" the problem? With a SQL client or from Java?
    • What is the local time zone of the JVM?
    • What is the MySQL Server time zone?
    • What is the version of the MySQL JDBC Driver?
    • Could you do a test with raw JDBC?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.