-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Affects: Spring Framework 5.3.3
When using SimpleJdbcInsert
without usingColumns()
, it tries to determine the columns from database metadata. When there is any exception, a warning is logged, but otherwise the exception is ignored:
Lines 415 to 419 in 9150980
catch (SQLException ex) { | |
if (logger.isWarnEnabled()) { | |
logger.warn("Error while retrieving meta-data for procedure columns: " + ex); | |
} | |
} |
This is fine as long as the exception occurs before any metadata could be read, because later this will cause an exception when generating the SQL string:
Lines 305 to 306 in 9150980
throw new InvalidDataAccessApiUsageException("Unable to locate columns for table '" + | |
getTableName() + "' so an insert statement can't be generated"); |
However, when an SQLException
occurs in columns.next()
...
Line 390 in 9150980
while (columns.next()) { |
... after the first column metadata has already been read and added to this.callParameterMetaData
, it continues with an incomplete list of columns and only inserts these, ignoring any other columns.
We have experienced this problem in our system very sporadically, and it's especially dangerous, because SimpleJdbcInsert.execute()
(as long as there are no NOT NULL
constraints for the columns) returns seemingly successfully, so the transactions are committed with incomplete/corrupted data.
It seems like we can work around the problem by calling usingColumns()
for all uses of SimpleJdbcInsert
.