Mybatis - 为 Hsql 指定 "useGeneratedKeys" 时出错
Mybatis - Error when specify "useGeneratedKeys" for Hsql
在Mybatis
映射器文件中,对于<insert>
语句,当添加属性 useGeneratedKeys="true"
时,会得到错误:
org.hsqldb.HsqlException: user lacks privilege or object not found: id
配置适用于 Postgresql
和 Mysql
,但不适用于 Hsql
。
hsql
中的id列定义为:
id BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY
当删除 属性 useGeneratedKeys="true"
时,它起作用了。
但为什么会这样呢?
是"id"的大小写。尝试将数据库中的列定义为
"id" BIGINT GENERATED ...
或者,在 MyBatis 中将列定义为 ID(大写)。
在Mybatis
映射器文件中,对于<insert>
语句,当添加属性 useGeneratedKeys="true"
时,会得到错误:
org.hsqldb.HsqlException: user lacks privilege or object not found: id
配置适用于 Postgresql
和 Mysql
,但不适用于 Hsql
。
hsql
中的id列定义为:
id BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY
当删除 属性 useGeneratedKeys="true"
时,它起作用了。
但为什么会这样呢?
是"id"的大小写。尝试将数据库中的列定义为
"id" BIGINT GENERATED ...
或者,在 MyBatis 中将列定义为 ID(大写)。