我有一个Mybatis映射器,应该在数据库表中创建一个条目。映射器定义如下-
<select id="saveUser" parameterType="User" resultMap="UserResultMap">
DROP TEMPORARY TABLE IF EXISTS temp_role_id;
CREATE TEMPORARY TABLE temp_role_id(id int);
INSERT INTO temp_role_id VALUES
<foreach collection="roles" item="role" separator=",">
(${role.id})
</foreach>;
call insert_user_sp('${name}', '${username}', '${email}', '${password}');
</select>
存储过程在下面定义-
DELIMITER //
CREATE PROCEDURE insert_user_sp(
u_name VARCHAR(40),
u_username VARCHAR(20),
u_email VARCHAR(40),
u_password VARCHAR(100)
)
BEGIN
INSERT INTO users(name, username, email, password)
VALUES(u_name, u_username, u_email, u_password);
SET @v_user_id = last_insert_id();
INSERT INTO user_roles(user_id, role_id)
SELECT @v_user_id, id from temp_role_id;
DROP TEMPORARY TABLE IF EXISTS temp_role_id;
SELECT id, name, username, email, password, created_at, modified_at
FROM users where id = @v_user_id;
END //
DELIMITER ;
mybatis给出的错误声明在下面-
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: 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 'CREATE TEMPORARY TABLE temp_role_id(id int);
INSERT INTO temp_role_id VA' at line 2
### The error may exist in mybatis/mappers/UserMapper.xml
### The error may involve UserMapper.saveUser-Inline
### The error occurred while setting parameters
### SQL: DROP TEMPORARY TABLE IF EXISTS temp_role_id; CREATE TEMPORARY TABLE temp_role_id(id int); INSERT INTO temp_role_id VALUES (4) ; call insert_user_sp('Ujjal Das', 'ujjaldas223', '[email protected]', '$2a$10$JlIb3BRXffYhMV8j9Wy2OuG2Wu53lGrHKexKspErzhi/JGwMhsvoO');
但是当我在mysql中执行相同的查询时,它会愉快地执行。
如果mysql执行相同查询没有任何问题,为什么mybatis抱怨相同?