私はJavaの世界が初めてです。そして、単純なクエリに問題があります:
<insert id="create" parameterType="models.entities.CategoryEntity">
set @catId := (select categoryId from Categories limit 1);
insert into Categories(CategoryId, Title, LeftValue, RightValue)
values(@catId, 'Test in', 1,2);
....
</insert>
mybatisで実行しようとすると失敗します:
PersistenceException occured : ### 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 'insert into Categories(CategoryId, Title, LeftValue, RightValue) values(' at line 2 ### The error may involve Category.create-Inline ### The error occurred while setting parameters ### 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 'insert into Categories(CategoryId, Title, LeftValue, RightValue) values(' at line 2
この行を削除すると:
set @catId := (select categoryId from Categories limit 1);
その後、すべてが大丈夫です。私は何を間違っていますか?jdbc または mybatis に問題がありますか? mybatis で mysql @variables を使用するには? mybatis で MySql ローカル変数を使用する例はありますか?