Shouldn't you be calling insert instead of update?

The update method always returns the number of rows updated.

The select key statement will not be executed unless you call the insert method.

Larry


On 4/29/05, Lieven De Keyzer <[EMAIL PROTECTED]> wrote:
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.


Reply via email to