MyBatis中单个映射器方法中的多个语句

时间:2014-04-20 16:09:38

标签: java mysql mybatis ibatis

我有一个mapper方法来删除表中的所有记录。但首先我需要从关联的联结表中删除所有记录。这就是我试过的:

@Delete("delete from COC_BLOCK_FIELD; delete from COC_BLOCK;")
void deleteBlocks();

这似乎很合理,但MyBatis在处理我的mapper时抛出异常:

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete from COC_BLOCK' at line 1
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: delete from COC_BLOCK_FIELD; delete from COC_BLOCK;
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete from COC_BLOCK' at line 1

我正在使用MyBatis 3.2.6,MySQL 5.5.35-1ubuntu1和MySQL Connector 5.1.26。

1 个答案:

答案 0 :(得分:9)

问题是我没有在JDBC URL中设置标志allowMultiQueries=true