本文介绍了MyBatis中单个映射器方法中的多个语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();

这看似合理,但MyBatis在处理我的映射器时抛出异常:

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

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

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

推荐答案

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

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

这篇关于MyBatis中单个映射器方法中的多个语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 23:43