added check for existing configuration of generated keys before calling update with a KeyHolder. (SPR-7564)
This commit is contained in:
parent
b06b5502e0
commit
97e047ed66
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException;
|
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException;
|
||||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterUtils;
|
import org.springframework.jdbc.core.namedparam.NamedParameterUtils;
|
||||||
|
|
@ -177,6 +178,12 @@ public class SqlUpdate extends SqlOperation {
|
||||||
* @return the number of rows affected by the update
|
* @return the number of rows affected by the update
|
||||||
*/
|
*/
|
||||||
public int update(Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException {
|
public int update(Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException {
|
||||||
|
if (!isReturnGeneratedKeys() && getGeneratedKeysColumnNames() == null) {
|
||||||
|
throw new InvalidDataAccessApiUsageException(
|
||||||
|
"The update method taking a KeyHolder should only be used when generated keys have " +
|
||||||
|
"been configured by calling either 'setReturnGeneratedKeys' or " +
|
||||||
|
"'setGeneratedKeysColumnNames'.");
|
||||||
|
}
|
||||||
validateParameters(params);
|
validateParameters(params);
|
||||||
int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params), generatedKeyHolder);
|
int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params), generatedKeyHolder);
|
||||||
checkRowsAffected(rowsAffected);
|
checkRowsAffected(rowsAffected);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue