Multiple statements in single mapper method in MyBatis

徘徊边缘 提交于 2019-12-21 19:43:07

问题


I have a mapper method to delete all records in a table. But first I need to delete all records from associated junction table. This is what I tried:

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

That seemed reasonable, yet MyBatis throws an exception when processing my 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

I'm using MyBatis 3.2.6, MySQL 5.5.35-1ubuntu1 and MySQL Connector 5.1.26.


回答1:


The problem was that I hadn't set the flag allowMultiQueries=true in the JDBC URL.



来源:https://stackoverflow.com/questions/23184619/multiple-statements-in-single-mapper-method-in-mybatis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!