ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Butler <jeffgbut...@gmail.com>
Subject Re: Strange problem with resultMaps
Date Thu, 06 May 2010 14:26:30 GMT
If you specify a resultMap, you need to specify a complete result map
- including all the fields from User.

Previously when you were not specifying a resultMap, iBATIS was
building one for you on the fly by introspecting the User class.  But
since you are now specifying the map yourself, iBATIS assumes it is
complete.

Jeff Butler


On Thu, May 6, 2010 at 5:27 AM, Metsovuori Juho
<Juho.Metsovuori@iltalehti.fi> wrote:
> Hey all,
>
> I have a this strange problem with resultMaps. When I use the query below to retrieve
a users information, everything works great.
>
>    public class User
>
>        private int id = 0;
>        private String username = "";
>        private String password = "";
>        private Timestamp registeredAt;
>        private Timestamp lastLogin;
>        private List<User> friends = new ArrayList<User>();
>
>    <sql id="table">
>        users
>        </sql>
>
>    <select id="getUser" parameterType="java.lang.String" resultType="User">
>            SELECT * FROM <include refid="table"/> WHERE username = #{username}
>      </select>
>
> But I need to add a resultMap, see below, to retrieve all the users friends. When I use
this resultMap, I don't get any of the users friends or even the users own username, but I
DO get the users password and other info. So do you have any ideas why this doesn't work,
and why I don't get the users username. The actualy sql queries do work, I tested them manually.
>
>    <resultMap id="friendByUsernameMap" type="User">
>            <association property="friends"
>                    column="username"
>                    javaType="java.util.ArrayList"
>                     select="eventstream.model.mapper.UserMapper.getFriendsByUsername"
/>
>    </resultMap>
>
>    <select id="getFriendsByUsername"
>        parameterType="java.lang.String"
>        resultType="User">
>            SELECT * FROM <include refid="table"/>
>            WHERE id IN
>                (SELECT userFriendId
>                FROM users_to_users, users
>                WHERE users.username = #{username}
>                AND users_to_users.userId = users.id)
>        </select>
>
> Thanks
> Juho
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Mime
View raw message