source

스프링 데이터 jpa hibernate mariadb timestamp fractional seconds가 삽입될 때 잘리는 이유는 무엇입니까?

goodcode 2022. 9. 4. 15:00
반응형

스프링 데이터 jpa hibernate mariadb timestamp fractional seconds가 삽입될 때 잘리는 이유는 무엇입니까?

다음과 같은 정의를 가진 열이 있습니다.

@Column(columnDefinition="DATETIME(3)")
private Timestamp timestamp;
public Timestamp getTimestamp() {return this.timestamp;}
public void setTimestamp(final Timestamp timestamp) {this.timestamp = timestamp;}
public String getFormattedTimestamp() {return Util.getFormattedTimestamp(this.timestamp);}

상위 엔티티를 저장하면(다른 @ManyToOne 관계에서 @ManyToOne 관계에 있음), 소수 초수는 항상 .000으로 설정됩니다만, 수동으로 테이블에 삽입하면 소수 초수는 적절히 유지됩니다.

결과 테이블 정의는 다음과 같습니다.

MariaDB [field_server]> show columns from device_timestamp;
+-----------------------+--------------+------+-----+---------+-------+
| Field                 | Type         | Null | Key | Default | Extra |
+-----------------------+--------------+------+-----+---------+-------+
| id                    | bigint(20)   | NO   | PRI | NULL    |       |
| deviceTimestampReason | int(11)      | YES  |     | NULL    |       |
| loggedIn              | bit(1)       | NO   |     | NULL    |       |
| reason                | varchar(255) | YES  |     | NULL    |       |
| timestamp             | datetime(3)  | YES  |     | NULL    |       |
+-----------------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

MariaDB [field_server]>

프로그램 트레이스는 다음을 나타냅니다.

webadmin - 2017-05-23 08:20:01,394 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:01,394 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@2aef651: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:01,394 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp#8]
webadmin - 2017-05-23 08:20:01,395 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [0] to parameter: [1]
webadmin - 2017-05-23 08:20:01,395 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [BOOLEAN] - [true]
webadmin - 2017-05-23 08:20:01,395 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:01,396 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [TIMESTAMP] - [2017-05-23 08:20:01.176]
webadmin - 2017-05-23 08:20:01,396 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [BIGINT] - [8]


webadmin - 2017-05-23 08:20:01,404 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:01,404 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@67f8586f: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:01,405 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp#9]
webadmin - 2017-05-23 08:20:01,405 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [1] to parameter: [1]
webadmin - 2017-05-23 08:20:01,405 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [BOOLEAN] - [false]
webadmin - 2017-05-23 08:20:01,406 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:01,406 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [TIMESTAMP] - [2017-05-23 08:20:03.176]
webadmin - 2017-05-23 08:20:01,406 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [BIGINT] - [9]


webadmin - 2017-05-23 08:20:01,622 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:01,623 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@42a057b6: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:01,623 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp#12]
webadmin - 2017-05-23 08:20:01,623 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [0] to parameter: [1]
webadmin - 2017-05-23 08:20:01,623 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [BOOLEAN] - [true]
webadmin - 2017-05-23 08:20:01,623 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:01,623 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [TIMESTAMP] - [2017-05-23 08:20:01.455]
webadmin - 2017-05-23 08:20:01,624 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [BIGINT] - [12]


webadmin - 2017-05-23 08:20:01,625 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:01,625 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@62036b05: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:01,625 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp#13]
webadmin - 2017-05-23 08:20:01,626 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [1] to parameter: [1]
webadmin - 2017-05-23 08:20:01,626 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [BOOLEAN] - [false]
webadmin - 2017-05-23 08:20:01,626 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:01,626 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [TIMESTAMP] - [2017-05-23 08:20:03.455]
webadmin - 2017-05-23 08:20:01,626 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [BIGINT] - [13]


webadmin - 2017-05-23 08:20:02,419 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:02,419 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@126320a8: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:02,419 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp_AUD#component[id,REV]{REV=org.hibernate.envers.DefaultRevisionEntity#1, id=8}]
webadmin - 2017-05-23 08:20:02,419 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - [0]
webadmin - 2017-05-23 08:20:02,420 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [0] to parameter: [2]
webadmin - 2017-05-23 08:20:02,420 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [BOOLEAN] - [true]
webadmin - 2017-05-23 08:20:02,420 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:02,420 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [TIMESTAMP] - [2017-05-23 08:20:01.176]
webadmin - 2017-05-23 08:20:02,420 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [6] as [BIGINT] - [8]
webadmin - 2017-05-23 08:20:02,420 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [7] as [INTEGER] - [1]


webadmin - 2017-05-23 08:20:02,421 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@12b0440b: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp_AUD#component[id,REV]{REV=org.hibernate.envers.DefaultRevisionEntity#1, id=9}]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - [0]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [1] to parameter: [2]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [BOOLEAN] - [false]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [TIMESTAMP] - [2017-05-23 08:20:03.176]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [6] as [BIGINT] - [9]
webadmin - 2017-05-23 08:20:02,422 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [7] as [INTEGER] - [1]


webadmin - 2017-05-23 08:20:02,439 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:02,440 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@76737130: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:02,440 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp_AUD#component[id,REV]{REV=org.hibernate.envers.DefaultRevisionEntity#1, id=12}]
webadmin - 2017-05-23 08:20:02,440 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - [0]
webadmin - 2017-05-23 08:20:02,440 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [0] to parameter: [2]
webadmin - 2017-05-23 08:20:02,440 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [BOOLEAN] - [true]
webadmin - 2017-05-23 08:20:02,440 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:02,440 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [TIMESTAMP] - [2017-05-23 08:20:01.455]
webadmin - 2017-05-23 08:20:02,441 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [6] as [BIGINT] - [12]
webadmin - 2017-05-23 08:20:02,441 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [7] as [INTEGER] - [1]


webadmin - 2017-05-23 08:20:02,442 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (?, ?, ?, ?, ?, ?, ?)
webadmin - 2017-05-23 08:20:02,442 [main] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - Registering statement [com.mysql.jdbc.JDBC42PreparedStatement@6f2a13c7: insert into device_timestamp_AUD (REVTYPE, deviceTimestampReason, loggedIn, reason, timestamp, id, REV) values (** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **, ** NOT SPECIFIED **)]
webadmin - 2017-05-23 08:20:02,442 [main] TRACE org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [ws.daley.field.persistence.model.DeviceTimestamp_AUD#component[id,REV]{REV=org.hibernate.envers.DefaultRevisionEntity#1, id=13}]
webadmin - 2017-05-23 08:20:02,442 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - [0]
webadmin - 2017-05-23 08:20:02,442 [main] TRACE org.hibernate.type.EnumType$EnumValueMapperSupport - Binding [1] to parameter: [2]
webadmin - 2017-05-23 08:20:02,442 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [BOOLEAN] - [false]
webadmin - 2017-05-23 08:20:02,442 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [VARCHAR] - [setupDataLoader]
webadmin - 2017-05-23 08:20:02,442 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [TIMESTAMP] - [2017-05-23 08:20:03.455]
webadmin - 2017-05-23 08:20:02,443 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [6] as [BIGINT] - [13]
webadmin - 2017-05-23 08:20:02,443 [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [7] as [INTEGER] - [1]

데이터는 소수점 초 단위로 삽입된 것으로 보입니다.다만, 다음의 예에서는, 데이터베이스에는 분수초가 송신되지 않는 것을 나타내고 있습니다.

MariaDB [field_server]> select * from device_timestamp;
+----+-----------------------+----------+-----------------+-------------------------+
| id | deviceTimestampReason | loggedIn | reason          | timestamp               |
+----+-----------------------+----------+-----------------+-------------------------+
|  8 |                     0 |         | setupDataLoader | 2017-05-23 08:20:01.000 |
|  9 |                     1 |          | setupDataLoader | 2017-05-23 08:20:03.000 |
| 12 |                     0 |         | setupDataLoader | 2017-05-23 08:20:01.000 |
| 13 |                     1 |          | setupDataLoader | 2017-05-23 08:20:03.000 |
+----+-----------------------+----------+-----------------+-------------------------+
4 rows in set (0.00 sec)

MariaDB [field_server]>

useFractionalSeconds를 jdbc.url에 포함시켰습니다.

jdbc.url=jdbc:mysql://localhost:3306/field_server?createDatabaseIfNotExist=true&useFractionalSeconds=true

여기 SQL이 있습니다.소수점 없음:

webadmin - 2017-05-23 19:17:05,005 [main] DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger - insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
Hibernate: insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (?, ?, ?, ?, ?)
/* conn id 1046 clock: 1495581425008 */ insert into device_timestamp (deviceTimestampReason, loggedIn, reason, timestamp, id) values (0, 1, 'test', '2017-05-23 19:17:00', 77);
webadmin - 2017-05-23 19:17:05,008 [main] TRACE com.mysql.jdbc.log.Slf4JLogger - send() packet payload:
host: 'localhost' threadId: '1046'
87 00 00 00 03 69 6e 73     . . . . . i n s 
65 72 74 20 69 6e 74 6f     e r t . i n t o 
20 64 65 76 69 63 65 5f     . d e v i c e _ 
74 69 6d 65 73 74 61 6d     t i m e s t a m 
70 20 28 64 65 76 69 63     p . ( d e v i c 
65 54 69 6d 65 73 74 61     e T i m e s t a 
6d 70 52 65 61 73 6f 6e     m p R e a s o n 
2c 20 6c 6f 67 67 65 64     , . l o g g e d 
49 6e 2c 20 72 65 61 73     I n , . r e a s 
6f 6e 2c 20 74 69 6d 65     o n , . t i m e 
73 74 61 6d 70 2c 20 69     s t a m p , . i 
64 29 20 76 61 6c 75 65     d ) . v a l u e 
73 20 28 30 2c 20 31 2c     s . ( 0 , . 1 , 
20 27 74 65 73 74 27 2c     . ' t e s t ' , 
20 27 32 30 31 37 2d 30     . ' 2 0 1 7 - 0 
35 2d 32 33 20 31 39 3a     5 - 2 3 . 1 9 : 
31 37 3a 30 30 27 2c 20     1 7 : 0 0 ' , . 
37 37 29                    7 7 ) 

MySQL 커넥터에서 MariaDB 커넥터로 전환하여 문제를 해결했습니다.기억하기로는 MariaDB 초기에는 MariaDB 커넥터가 없었기 때문에 MySQL 커넥터를 사용해야 했습니다.보아하니 그건 더 이상 사실이 아닌 것 같다.MariaDB를 사용하는 경우 MariaDB 커넥터가 필요할 것 같습니다.

나는 그 문제가 데이터 소스로 거슬러 올라간다고 생각한다.

mysql> SELECT NOW(), NOW(3);
+---------------------+-------------------------+
| NOW()               | NOW(3)                  |
+---------------------+-------------------------+
| 2017-05-23 07:39:29 | 2017-05-23 07:39:29.110 |
+---------------------+-------------------------+

내 말은, 소스에 밀리초가 없다면.000는 삽입 중에 공급됩니다.

또, 왜 python으로 시간을 생성합니까?보시는 바와 같이 MySQL은 소수점 이하 6자리까지 시간을 생성할 수 있습니다.

여러 SQL 문에 대해 균일한 시간이 필요한 경우 한 번 캡처한 후 다시 사용할 수 있습니다.

mysql> SELECT @ts := NOW(6);
+----------------------------+
| @ts := NOW(6)              |
+----------------------------+
| 2017-05-23 07:43:35.584183 |
+----------------------------+
mysql> SELECT @ts, NOW(6);
+----------------------------+----------------------------+
| @ts                        | NOW(6)                     |
+----------------------------+----------------------------+
| 2017-05-23 07:43:35.584183 | 2017-05-23 07:43:53.821409 |
+----------------------------+----------------------------+
mysql> SELECT @ts, NOW(6);
+----------------------------+----------------------------+
| @ts                        | NOW(6)                     |
+----------------------------+----------------------------+
| 2017-05-23 07:43:35.584183 | 2017-05-23 07:43:55.570200 |
+----------------------------+----------------------------+

주의: 버전 5.6.4는 프랙셔널 초가 최초로 완전하게 실장된 시점이라고 생각합니다.

정밀 테스트

10.0.28 사용:

mysql> create table now3 (dt datetime(3), ts timestamp(3));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into now3 (dt,        ts)
                 values (now(),     now()),
                        (curdate(), curdate()),
                        (now(3),    now(3));
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0
mysql> insert into now3 (dt, ts)
                 values ('2017-05-23 19:19:13.123',
                         '2017-05-23 19:19:13.123');
Query OK, 1 row affected (0.00 sec)

mysql> select * from now3;
+-------------------------+-------------------------+
| dt                      | ts                      |
+-------------------------+-------------------------+
| 2017-05-23 19:19:13.000 | 2017-05-23 19:19:13.000 | -- NOW() has mo ms
| 2017-05-23 00:00:00.000 | 2017-05-23 00:00:00.000 | -- CURDATE() has no time
| 2017-05-23 19:19:13.842 | 2017-05-23 19:19:13.842 | -- NOW(3) worked
| 2017-05-23 19:19:13.123 | 2017-05-23 19:19:13.123 | -- from string
+-------------------------+-------------------------+

mysql> select @@version;
+--------------------------+
| @@version                |
+--------------------------+
| 10.0.28-MariaDB-1~jessie |
+--------------------------+

그래서... 들어오는 데이터가 문제인 것 같아요.실제 SQL을 덤프할 수 있습니까?

언급URL : https://stackoverflow.com/questions/44135262/why-is-spring-data-jpa-hibernate-mariadb-timestamp-fractional-seconds-truncated

반응형