loaddata loads TIME column as Date with 0 Time.

Description

When loading data through csv files for "TIME" columns , in database it is stored as 0.

2019-09-11 14:12:38.252 INFO 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : SELECT * FROM LIQUIBASE_DEMO.DATABASECHANGELOG ORDER BY DATEEXECUTED ASC, ORDEREXECUTED ASC
2019-09-11 14:12:38.253 INFO 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT FROM LIQUIBASE_DEMO.DATABASECHANGELOGLOCK
2019-09-11 14:12:38.259 DEBUG 12924 — [ main] liquibase.util.MD5Util : Computed checksum for createTable:[
columns=[
[
[
nullable="false"
primaryKey="true"
primaryKeyName="PK_T_TIME"
primaryKeyTablespace="T_TIME_INDEX"
]
name="ID"
type="NUMBER"
],
[
[
nullable="false"
]
name="START_OF_DAY_TIME"
type="time"
]
]
schemaName="LIQUIBASE_DEMO"
tableName="T_TIME"
tables... [truncated in log] as 60d795062d1ef01ba1fa0337e8f270e8
2019-09-11 14:12:38.259 DEBUG 12924 — [ main] liquibase.util.MD5Util : Computed checksum for 8:60d795062d1ef01ba1fa0337e8f270e8: as 37696812c101bf0850e2389f984387ee
2019-09-11 14:12:38.260 DEBUG 12924 — [ main] i.s.SpringLiquibase$SpringResourceOpener : Opening file:/C:/Users/d532315/cassini/Liquibase-demo/sample/target/classes/db/changelog/referenceData/time-load.csv as classpath:/db/changelog/referenceData/ti
me-load.csv
2019-09-11 14:12:38.264 DEBUG 12924 — [ main] liquibase.util.MD5Util : Computed checksum for inputStream as 3903a8d9e61de2cbeea5222f6e555fbd
2019-09-11 14:12:38.264 DEBUG 12924 — [ main] liquibase.util.MD5Util : Computed checksum for T_TIME:8:3903a8d9e61de2cbeea5222f6e555fbd as 9a4488d9ea83ac781f31bcf087aedc0d
2019-09-11 14:12:38.264 DEBUG 12924 — [ main] liquibase.util.MD5Util : Computed checksum for 8:9a4488d9ea83ac781f31bcf087aedc0d: as ca153d9f6834ed2e02aa49e07ddc175e
2019-09-11 14:12:38.265 DEBUG 12924 — [ main] l.changelog.visitor.UpdateVisitor : Running Changeset:db/changelog/db.changelog-time.yaml::time-create:rashant
2019-09-11 14:12:38.265 DEBUG 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : Changeset db/changelog/db.changelog-time.yaml::time-create:rashant
2019-09-11 14:12:38.265 DEBUG 12924 — [ main] liquibase.changelog.ChangeSet : Reading ChangeSet: db/changelog/db.changelog-time.yaml::time-create:rashant
2019-09-11 14:12:38.266 DEBUG 12924 — [ main] liquibase.database.core.H2Database : Executing Statement: liquibase.statement.core.CreateTableStatement@7f353a0f
2019-09-11 14:12:38.266 INFO 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : CREATE TABLE LIQUIBASE_DEMO.T_TIME (ID NUMBER NOT NULL, START_OF_DAY_TIME time NOT NULL, CONSTRAINT PK_T_TIME PRIMARY KEY (ID))
2019-09-11 14:12:38.269 DEBUG 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : 0 row(s) affected
2019-09-11 14:12:38.269 INFO 12924 — [ main] liquibase.changelog.ChangeSet : Table T_TIME created
2019-09-11 14:12:38.269 INFO 12924 — [ main] liquibase.changelog.ChangeSet : ChangeSet db/changelog/db.changelog-time.yaml::time-create:rashant ran successfully in 4ms
2019-09-11 14:12:38.269 INFO 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : SELECT MAX(ORDEREXECUTED) FROM LIQUIBASE_DEMO.DATABASECHANGELOG
2019-09-11 14:12:38.275 INFO 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : INSERT INTO LIQUIBASE_DEMO.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQU
IBASE, DEPLOYMENT_ID) VALUES ('time-create', 'Prashant', 'db/changelog/db.changelog-time.yaml', NOW(), 1, '8:37696812c101bf0850e2389f984387ee', 'createTable tableName=T_TIME', '', 'EXECUTED', NULL, NULL, '3.6.3', '8207558253')
2019-09-11 14:12:38.276 DEBUG 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : 1 row(s) affected
2019-09-11 14:12:38.276 DEBUG 12924 — [ main] l.changelog.visitor.UpdateVisitor : Running Changeset:db/changelog/db.changelog-time.yaml::time-load:rashant
2019-09-11 14:12:38.276 DEBUG 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : Changeset db/changelog/db.changelog-time.yaml::time-load:rashant
2019-09-11 14:12:38.277 DEBUG 12924 — [ main] liquibase.changelog.ChangeSet : Reading ChangeSet: db/changelog/db.changelog-time.yaml::time-load:rashant
2019-09-11 14:12:38.277 DEBUG 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : WARNING The following SQL may change each run and therefore is possibly incorrect and/or invalid:
2019-09-11 14:12:38.277 DEBUG 12924 — [ main] i.s.SpringLiquibase$SpringResourceOpener : Opening file:/C:/Users/d532315/cassini/Liquibase-demo/sample/target/classes/db/changelog/referenceData/time-load.csv as classpath:/db/changelog/referenceData/ti
me-load.csv
2019-09-11 14:12:38.281 DEBUG 12924 — [ main] liquibase.database.core.H2Database : Executing Statement: liquibase.statement.BatchDmlExecutablePreparedStatement@47248a48
2019-09-11 14:12:38.282 INFO 12924 — [ main] l.s.ExecutablePreparedStatementBase : INSERT INTO LIQUIBASE_DEMO.T_TIME(ID, START_OF_DAY_TIME) VALUES(?, ?)
2019-09-11 14:12:38.282 DEBUG 12924 — [ main] l.s.ExecutablePreparedStatementBase : Number of columns = 2
2019-09-11 14:12:38.285 DEBUG 12924 — [ main] l.s.ExecutablePreparedStatementBase : Applying column parameter = 1 for column ID
2019-09-11 14:12:38.286 DEBUG 12924 — [ main] l.s.ExecutablePreparedStatementBase : value is numeric = 1
2019-09-11 14:12:38.286 DEBUG 12924 — [ main] l.s.ExecutablePreparedStatementBase : Applying column parameter = 2 for column START_OF_DAY_TIME
*2019-09-11 14:12:38.286 DEBUG 12924 --- [ main] l.s.ExecutablePreparedStatementBase : value is date = 07:00:00*
2019-09-11 14:12:38.289 INFO 12924 — [ main] l.s.BatchDmlExecutablePreparedStatement : Executing JDBC DML batch was successful. 1 operations were executed, 1 individual UPDATE events were confirmed by the database.
2019-09-11 14:12:38.289 INFO 12924 — [ main] liquibase.changelog.ChangeSet : Data loaded from referenceData/time-load.csv into T_TIME
2019-09-11 14:12:38.289 INFO 12924 — [ main] liquibase.changelog.ChangeSet : ChangeSet db/changelog/db.changelog-time.yaml::time-load:rashant ran successfully in 13ms
2019-09-11 14:12:38.291 INFO 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : INSERT INTO LIQUIBASE_DEMO.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQU
IBASE, DEPLOYMENT_ID) VALUES ('time-load', 'Prashant', 'db/changelog/db.changelog-time.yaml', NOW(), 2, '8:ca153d9f6834ed2e02aa49e07ddc175e', 'loadData tableName=T_TIME', '', 'EXECUTED', NULL, NULL, '3.6.3', '8207558253')
2019-09-11 14:12:38.291 DEBUG 12924 — [ main] liquibase.executor.jvm.JdbcExecutor : 1 row(s) affected

This problem is not present in 3.5.1 version of liquibase.

The problem seems to be in ExecutablePreparedStatementBase.applyColumnParameter() method.

} else if (col.getValueDate() != null) {
LOG.debug(LogType.LOG, "value is date = " + col.getValueDate());
if (col.getValueDate() instanceof Timestamp) {
stmt.setTimestamp(i, (Timestamp) col.getValueDate());
} else {
stmt.setDate(i, new java.sql.Date(col.getValueDate().getTime()));
}
}

This goes in else condition when it finds a col.getValueDate() of type java.sql.Time and it creates a Date with the specified Time. This date always have time fields(hour/.min/sec ) set to 0.
Instead it should use stmt.setTime(i, (Time) col.getValueDate()); when it finds a valueDate that is of type Time.

Environment

database H2, Oracle

Status

Assignee

Unassigned

Reporter

prashant sharma

Labels

None

Components

Affects versions

Priority

Major
Configure