-
Notifications
You must be signed in to change notification settings - Fork 38.5k
NamedParameterJdbcTemplate.batchUpdate does not individually apply the SQL type from each SqlParameterSource argument #26071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for raising this! Looks like a regression caused by #21935 (about two years ago). We used to derive named parameter replacement from the first batch arguments (which is still necessary), but since then we're also taking the SQL type indications from the first argument entry only. I guess most batches use the same types anyway, otherwise we'd have noticed earlier. In any case, this is easy enough to address through |
This is available in the latest snapshots now: 5.3.2, 5.2.12, 5.1.20 (see https://repo.spring.io/snapshot/org/springframework/spring-framework-bom/). It'd be great if you could give the fix an early try, we're going to release all of the above in early December. It turned out that it was indeed a regression in 5.1.x. I've backported the test to 5.0.x and 4.3.x as well where it passes right away. |
Uh oh!
There was an error while loading. Please reload this page.
The class NamedParameterJdbcTemplate has following method:
The method signature suggests fine-grained control over the SQL type hints, so that these could be customised for each element in the array, however, this is not true.
As a matter of fact, only the SQL hints for the first element in the array are processed, they are then applied to all the elements in the batch by PreparedStatementCreatorFactory.
This can lead to exceptions within the JDBC driver, for example when using MySQL/MariaDB. Consider the following table definition and inserts:
Now consider this Java:
This will throw an exception in the MySQL driver because Types.NULL from the first element will be applied to the second element as well.
Cannot convert class java.lang.String to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Conversion from java.lang.String to NULL is not supported.
The text was updated successfully, but these errors were encountered: