我正在使用 IBATIS 2.3.4 版本。数据库是 MS SQL Server。
我正在尝试在表 T_PROFILE 中插入记录,该表具有 Identity 主列自动生成的值。
我的 IBATIS 配置是
<insert id="insertProfile" parameterClass="profileDO" useGeneratedKeys="true" keyProperty="profileId">
INSERT INTO T_PROFILE (E_ID,PROFILE_NAME,DEFAULT_PROFILE)
VALUES(#eId#, #profileName#, #isDefaultProfile#)
<selectKey resultClass="java.lang.Long" keyProperty="profileId" >
SELECT @@IDENTITY AS profileId
</selectKey>
</insert>
它给出了错误
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: Attribute "useGeneratedKeys" must be declared for element type "settings".
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:55)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:339)
... 160 more
Caused by: org.xml.sax.SAXParseException: Attribute "useGeneratedKeys" must be declared for element type "settings".