ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lieven De Keyzer" <lieven_dekey...@hotmail.com>
Subject selectKey and MySql problem
Date Fri, 29 Apr 2005 14:30:26 GMT
I've searched the archive for this issue, but still couldn't solve it.
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.



Mime
View raw message