You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi~
I found a small problem while using Spring Batch. I , it would be better that spring-jdbc's MySQLMaxValueIncrementer supports MYSQL safe_update_mode (or safe mode)
Mysql safe_update Mode
First if we have a MySQL database instance with global option:
SET global sql_safe_updates=1
Then the 'Incrementer' will fail:
Exception in thread "main" org.springframework.dao.DataAccessResourceFailureException:
Could not increment value for tab_sequence sequence table;
nested exception is java.sql.SQLException:
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
at org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer.getNextKey(MySQLMaxValueIncrementer.java:148)
at org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer.nextIntValue(AbstractDataFieldMaxValueIncrementer.java:123)
Enabling sql_safe_updates causes UPDATE and DELETE statements to produce an error if they do not specify a key constraint in the WHERE clause, or provide a LIMIT clause, or both.
Solution
If we add limit 1, then this statement will success.
sbrannen
changed the title
Mysql safe_update support for MySQLMaxValueIncrementer advice
Support MySQL sql_safe_updates in MySQLMaxValueIncrementer
Apr 27, 2021
sbrannen
changed the title
Support MySQL sql_safe_updates in MySQLMaxValueIncrementer
Support MySQL safe updates mode in MySQLMaxValueIncrementer
Apr 28, 2021
Prior to this commit, MySQLMaxValueIncrementer could not be used when
the MySQL database was configured to use safe-updates mode.
See https://dev.mysql.com/doc/refman/8.0/en/mysql-tips.html#safe-updates
This commit introduces a `limit 1` clause to the generated update
statement to allow MySQLMaxValueIncrementer to be compatible with
MySQL safe-updates mode.
Closesspring-projectsgh-26858
lxbzmy
pushed a commit
to lxbzmy/spring-framework
that referenced
this issue
Mar 26, 2022
Prior to this commit, MySQLMaxValueIncrementer could not be used when
the MySQL database was configured to use safe-updates mode.
See https://dev.mysql.com/doc/refman/8.0/en/mysql-tips.html#safe-updates
This commit introduces a `limit 1` clause to the generated update
statement to allow MySQLMaxValueIncrementer to be compatible with
MySQL safe-updates mode.
Closesspring-projectsgh-26858
Affects: all
Hi~
I found a small problem while using Spring Batch. I , it would be better that spring-jdbc's
MySQLMaxValueIncrementer
supports MYSQL safe_update_mode (or safe mode)Mysql safe_update Mode
First if we have a MySQL database instance with global option:
Then the 'Incrementer' will fail:
Code from spring-jdbc
spring-framework/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/MySQLMaxValueIncrementer.java
Lines 143 to 144 in 5b1ab31
As Mysql Reference says:
Solution
If we add
limit 1
, then this statement will success.or turn off sql_safe_updates (may be ignored by some dba middleware )
or
Spring Batch
Here are some schema in Spring Batch project.
https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mysql.sql
for example
The
ID
column neither is a primary key, nor a indexed column. The safe_update_mode will raise an exception.Appendix
A quick test code:
The text was updated successfully, but these errors were encountered: