Oracle设置
< insert id ="insertProduct-ORACLE" parameterClass ="com.domain.Product" >
< selectKey resultClass ="int" keyProperty ="id" type ="pre" >
selectKey >
insert >
MS SQL Server 配置
< insert id ="insertProduct-MS-SQL" parameterClass ="com.domain.Product" >
< selectKey resultClass ="int" keyProperty ="id" type ="post" >
selectKey >
insert >
上述MS SQL Server 配置随是官网提供的配置,但实际上却恰恰隐患重重!按下述配置,确保获得有效主键。
< insert id ="insertProduct-MS-SQL" parameterClass ="com.domain.Product" >
< selectKey resultClass ="int" keyProperty ="id" >
SELECT SCOPE_IDENTITY() AS ID ]]>
selectKey >
insert >
MySQL配置
< insert id ="insertProduct-Mysql" parameterClass ="com.domain.Product" >
< selectKey resultClass ="int" keyProperty ="id" >
selectKey >
insert >