hlorofils
unread,Jun 2, 2010, 4:04:06 AM6/2/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybatis-user
I'm using mybatis 3.0.1, PostgreSQL 8.4 and have some trouble
understanding the difference between 'id' and 'result' elements. take
a look at this mapping:
<select id="getTestStories" resultMap="rmTestStory">
SELECT story_id, author, vote_type_id, vote_count FROM (
VALUES
(1, 'author1', 2, 1),
(1, 'author1', 3, 2),
(1, 'author1', 4, 4),
(2, 'author2', 1, 1),
(2, 'author2', 3, 2),
(2, 'author2', 4, 2)
) AS Votes (story_id, author, vote_type_id, vote_count)
ORDER BY 1 ASC
</select>
<resultMap id="rmTestStory" type="TestStory">
<id property="id" column="story_id"/>
<result property="author" column="author"/>
<collection property="voteCounts" ofType="VoteCount"
javaType="ArrayList">
<result property="voteTypeId" column="vote_type_id"/>
<result property="count" column="vote_count"/>
</collection>
</resultMap>
the important part is <result property="voteTypeId"
column="vote_type_id"/>. if it is set as an 'id' element, I get funny
results - for story with story_id = 2 and vote_type_id = 4 the
vote_count is 4 which is obviously wrong. on the other hand the
results are correct if I set the same mapping as 'result' element.