<insert id="insert" parameterType="com.hismax.apptPlatform.entity.table.Userinfo"> <selectKey order="BEFORE" resultType="long" keyProperty="userId"> SELECT seq_userinfo.nextval as userId from dual; </selectKey> insert into USERINFO (USER_ID, USER_NAME, ID_TYPE, ID_NO, PASSWORD, TYPE, LINK_COUNT, CREATE_USER ) values (#{userId}, #{userName}, #{idType}, #{idNo}, #{password}, #{type}, #{linkCount}, #{createUser} ) </insert>
使用上述配置设定insert语句,一直报一下错误:
{
"timestamp": "2018-05-21 10:32:41",
"status": 500,
"error": "Internal Server Error",
"message": "Error selecting key or setting result to parameter object. Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符\n\n; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符\n",
"path": "/appt/user/register"
}
查了下序列,已经用了20多个序列了,就是说mybaits可以成功获取序列,但是不能赋值进insert语句。搞了好久之后,搞不定,跟同事的代码对比了一下,发现有一个地方不同:
SELECT seq_userinfo.nextval as userId from dual;
语句最后有个 ; 号!!!
去掉;,跑通了。
使用selectKey后数据库提示无效的字符。原因:selectKey里面的SQL语句不能添加";",如果添加了分号,就无法赋值到insert中,从而报错。