org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty 'sessionId' in'org.apache.ibatis.reflection.SystemMetaObject$NullObject'.
No setter found for the keyProperty 'sessionId' in 'org.apache.ibatis.reflection.SystemMetaObject$NullObject'
<insert id="createSession" useGeneratedKeys="true" keyProperty="sessionId" parameterType="com.example.demo.entity.SessionInfo">
insert into session(last_time) values(now());
</insert>
这是MyBatis提供的返回自增主键我出现的问题
正常情况下都需要传一个对象进去,由于我的插入只是更新时间的,没有其他属性,所以只传了时间参数。
解决途径是自增主键对应的Java对象的属性,将此属性所在的对象传进方法,还要注意keyProperty要与对象的Java属性对应起来。