To ID or not to ID - a mapping issue

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

To ID or not to ID - a mapping issue

Nicolai Willems
Hey mybatis

I have some trouble getting round the ID mechanism(I guess thats it)
in MyBatis.

I have a stored procedure returning one resultset with 2 columns, one
with a name and the other with an associated number.
The problem is that when specifying the needed association, I get too
few results(instead of 18 I get 2).
It maybe coincidence but it seems that the number column now acts as
ID, and therefore only the distinct ones is put in my result(Why I say
the "ID mechanism").

I keep the number in a parent object and the name(which in fact is the
id) in a child, see end of post for real java code:

When trying to "just" get a list of Holder objects, I get the real
number of returned rows(also changing the usr property to string).
But when trying to use the User object it fails and only returns the
distinct numbers.

First, how is this behavior explained? I really don't understand why
this occurs.
Secondly how can I solve this in my project?

/Nicolai

====== JAVA Code ======
class Holder{
    private Integer num;
    private User usr;

    /* Getters'n'Setters... */
}

class User{
    private String name;
    /* Getters'n'Setters... */
}

====== Mapper ======
<mapper>
...
    <resultMap id="userNumberMap" type="dk.nwtestapp.Holder">
        <result column="Number" property="num" />
        <association javaType="dk.nwtestapp.User" property="usr">
            <result column="UserName" property="name" />
        </association>
    </resultMap>
...
    <select id="getCurrentQueueAgents" resultMap="userNumberMap">
        call sp_get_users_numbers();
    </select>
...
</mapper>