Saving milliseconds in MySQL timestamp column using Hibernate

I am trying to save java Date with milliseconds in a MySQL timestamp column using Hibernate, but milliseconds are always saved as .000 .

The definition of a column in sleep mode is as follows:

 @Type(type="timestamp")`` private Timestamp timestamp; 

The column database is declared as TIMESTAMP(3)

I tried various combinations, including Date , but none of them helped. I am using MySQL 5.6.25, Connector / J version 5.1.37, Hibernate 4.0.1.

I have been doing this for a while, but could not find a solution that works for me.

Any help would be appreciated.

+5
source share
1 answer

Have you tried using DATETIME(3) or TIMESTAMP(4) ? I believe both of them will give you milliseconds. If you are trying to get a millisecond time when an interaction occurs, such as updating a row, you can use ON UPDATE DATETIME(3)

0
source

Source: https://habr.com/ru/post/1240800/


All Articles