2017-4-2
Use java.util.Date and Java.util.Calendar in Java to represent the time, date type. The use of year , date, time, TIMESTAMP, DATETIME Five data types in Mysql represents the date, which leads to the question of how the Java date type maps to the date type of the database. This article summarizes the solutions for using Hibernate @Temporal annotations.
to decorate the data type of a Java entity class using @Temporal annotations
- Specifies @Temporal the Value property, which corresponds to the database mapping relationship:
- temporaltype.date --> date
- temporaltype.time --> time
- temporaltype.timestamp --> timestamp
- For example code:
1 @Temporal (temporaltype.date) 2 Public Date Birth; 3 // get, set method
Differences between Mysql time and date types
differences between MySQL five time and date types
| type |
occupied space |
format |
scope |
| Year |
1byte |
' YYYY ' |
Year (4): ' 1901 ' to ' 2155 ' Year (2): ' 0 ' to ' 69 ' for 2000-2,069 years |
| DATE |
3byte |
' Yyyy-mm-dd ' |
' 1000-01-01 ' to ' 9999-12-31 ' |
| time |
3byte |
" HH:MM:SS ' |
-838:59:59 " to ' 838:59:59 |
| timestamp |
4byte |
" Yyyy-mm-dd hh:mm:ss ' |
' 1970-01-01 00:00:01 ' UTC to " 2038-01-19 03:14:07 '  UTC |
| Datetime |
8byte |
' Yyyy-mm-dd HH:MM:SS ' |
' 1000-01-01 00:00:00 ' to ' 9999-12-31 23:59:59 ' |
Reference Blog: http://lgdvsehome.blog.51cto.com/3360656/1243676
Hibernate @Temporal annotations Handle the mappings between Java and MySQL time and date types