org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;错误的SQL语法从model_state_history.model_id = model.ID的model_state_history内连接模型中删除model_state_history,其中model.PACKAGE_ID = ?;嵌套的异常是org.h2.jdbc.JdbcSQLException:语法错误在SQL语句“从model_state_history.model_ID = model.id的* model_state_history内连接模型中删除model_state_history = model.package_id =?";SQL语句:
并将上面的内容抛到输出中。在我看来,我没有看到语法错误。我正在使用MySQL数据库。上面的SQL语法有什么明显的错误吗?
使用DELETE FROM语法也会产生语法错误。
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;错误的SQL语法从model_STATE_HISTORY.model_ID = model.id的model_state_history内连接模型中删除model.package_id = ?;嵌套的异常是org.h2.jdbc.JdbcSQLException: org.h2.jdbc.JdbcSQLException语句中的语法错误“从model_STATE_HISTORY内部*连接模型中删除model_state_history.model_id = model.ID,其中model.PACKAGE_ID =?";SQL语句:从model_state_history内连接模型中删除model_state_history.model_id = model.id,其中model.package_id =?42000-176
这就是正在运行的代码
@Transactional
private int deleteAllModels(Long packageId) throws DataAccessException {
return new NamedParameterJdbcTemplate(dataSource).update(
"DELETE FROM model_state_history INNER JOIN model ON model_state_history.version_id = model.id WHERE model.package_id = :package_id",
ImmutableMap.of("package_id", packageId));发布于 2014-11-11 07:42:13
再考虑一下,我认为您可能对联接语法有问题。你在写
从..。内部连接..。关于msh.version_id = m.id ,其中 m.package_id = :package_id
我认为WHERE应该是一个AND,所以查询将变成:
"DELETE FROM model_state_history INNER JOIN model
ON model_state_history.version_id = model.id AND model.package_id = :package_id"因为WHERE引用了DELETE语句,它的“作用域”中没有model表。
干杯,
https://stackoverflow.com/questions/26859869
复制相似问题