I'm working on a webbased application using Struts 1.2.4, iBatis SQL Maps 2.0 and iBatis DAO Framework. I also try to stick close to the concept of JPetStore 4.0.5.
The problem I encounter is with the <selectKey> stanza.
These are in Folder.xml
<typeAlias alias="folder" type="com.vub.bookmarked.domain.Folder"/>
<resultMap id="folderResult" class="folder"> <result property="folderId" column="folder_id"/> <result property="parentId" column="parent_id"/> <result property="owner" column="owner"/> <result property="foldername" column="foldername"/> </resultMap>
<insert id="insertFolder" parameterClass="folder">
INSERT INTO folder (parent_id, owner, foldername)
VALUES (#parentId#, #owner#, #foldername#)
<selectKey resultClass="int" keyProperty="folderId">
SELECT LAST_INSERT_ID() AS folderId
</selectKey>
</insert>
I catch this key in FolderSqlMapDao.java:
public int insertFolder(Folder folder) {
int key = update("insertFolder", folder);
return key;
}But this key always seems to be the first inserted element, so 1 . For all the folders that get inserted afterwards, selectKey always returns this 1.

