I have a mapping for a Java class Bookmark that looks like this:
<resultMap id="bookmarkResult" class="bookmark">
<result property="bookmarkId" column="bookmark_id"/>
<result property="folderId" column="folder_id"/>
<result property="url" column="url"/>
<result property="bookmarkname" column="bookmarkname"/>
<result property="updated" column="updated"/>
<result property="changed" column="changed"/>
<result property="scanInterval" column="scan_interval"/>
<result property="cache" column="cache" jdbcType="BLOB"/>
<result property="notificationWays" column="bookmark_id"
select="getNotificationListByBookmarkId"/>
</resultMap>
Now, getting a bookmark is no problem with:
<select id="getBookmarkById" resultMap="bookmarkResult"
parameterClass="int">
SELECT *
FROM bookmark
WHERE bookmark_id = #value#
</select>
<select id="getNotificationListByBookmarkId" resultMap="bookmarkResult"
parameterClass="int">
SELECT notification_way
FROM notifications
WHERE bookmark_id = #value#
</select>
But if I insert a bookmark, this Bookmark's NotificationWays array, can have
values. This number is not a constant. Can I, when I insert, or update a
bookmark, also insert or update these notificationWays in the notifications
table?
Now I have:
<update id="updateBookmark" parameterClass="bookmark">
UPDATE bookmark
SET folder_id = #folderId#, bookmarkname = #bookmarkname#,
url = #url#, changed = #changed#, updated= #updated#,
scan_interval = #scanInterval#, cache = #cache#
WHERE bookmark_id = #bookmarkId#
</update>
which updates the bookmark table allright, but of course does nothing to the
notifications table.
In fact, it's even complexer than this, because when a certain notification
is given as parameter and it is not present yet, is should be inserted, when
it is present, nothing should happen, and when it's not given as parameter,
it should be deleted.