错误详情:
org.springframework.jdbc.UncategorizedSQLException: Error getting generated key or setting result to parameter object. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 必须执行该语句才能获得结果。
; uncategorized SQLException; SQL state [null]; error code [0]; 必须执行该语句才能获得结果。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 必须执行该语句才能获得结果。
问题出现在一个插入语句中 ,之前做的项目数据库中的主键是自动递增的,新项目用的erp的数据库,xml文档都是复制粘贴的,结果一插入GG了,看一下插入语句:
<insert id="insert" useGeneratedKeys="true" keyProperty="id"
parameterType="com.xxx.xxx.xxx.xdo.T_OrganizationDO">
insert into t_Organization (
<include refid="sqlKey" />
) values (
<include refid="sqlValue" />
)
</insert>
问题出现在了 :useGeneratedKeys=“true”
这个关键字的意思是插入本条记录并将自动递增的id反写到传入的对象参数中,erp中的表id并没有设置自动递增,所以这个地方自然报错,直接干掉就可以咯!