Skip to content

SimpleJdbcInsert (sporadically) does not insert all columns #26486

@j8zdev

Description

@j8zdev

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:

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:

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() ...

... 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.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions