[Hibernate] The date type of the base value type mapping

Source: Internet
Author: User

Hibernate basic value type mapping in Date type support Date,time,timestamp These three options, where

Date: The date type in the corresponding database, indicating that only dates are displayed

Time: The date type in the corresponding database, indicating that only times are displayed

Timestamp: The timestamp type in the corresponding database, which corresponds to a datetime type if the database supports a DateTime type, indicating that the DateTime is displayed (this is a guess after I have tested it).

Following excerpt from: Open source China

The fields used to store the full time in MySQL include TIMESTAMP and DATETIME two. A lot of people in the choice of Time field is a bit dizzy, in the end I choose which one, they two what is the difference?

Date Range

TIMESTAMP support from ' 1970-01-01 00:00:01′ to ' 2038-01-19 03:14:07′ UTC. This time may not be a problem for the people who are currently working, and we can persist until we retire, but for some young readers, there will be bug2k+38 problems.

DATETIME from ' 1000-01-01 00:00:00′ until ' 9999-12-31 23:59:59′.

Given the difference in scope between the two, your current event log uses TIMESTAMP without any problems, but if it is to record your grandfather and grandson's birthday, it will be DATETIME.

In addition, I suggest that if it is related to the current time, you can choose TIMESTAMP. For example, the time to add a record, or to select DATETIME.

Storage-related comparisons

TIMESTAMP requires 4 bytes of storage space, while DATETIME requires 8 bytes

[Hibernate] The date type of the base value type mapping

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.