Page 31 of the user guide has an impressive display of resultMap
functionality which puts collections etc. inside without having to get
each level.
E.g. if you have a users table, and a roles table which has user id, I
assume you can retrieve a user with all his roles in one hit.
The UserMapper.xml might be something like this:
<resultMap id="userRolesResultMap" type="com.skillkash.ge.beans.User">
<result property="id" column="user_id"/>
<collection property="roles" ofType="com.skillkash.ge.beans.Role">
<result property="id" column="role_id"/>
</collection>
</resultMap>
<select id="select" resultType="userRolesResultMap">
select
u.id as user_id
,name
,
r.id as stake_id
,r.description
from users u, roles r
where
u.id = #{value}
</select>
and then 2 beans like this:
package bla
public class User {
private long id;
private String name;
private List<Role> roles;
// getters and setters for id, name and roles
}
package bla
public class Role {
private long id;
private String description;
// getters and setters for id, description
}
So, without any exmaple to go by, Im guessing that the rusult map can
magically put the roles into the users.
But all I get is this error:
Error resolving class . Cause: org.apache.ibatis.type.TypeException:
Could not resolve type alias 'userRolesResultMap'.
I dont get it, the definition of the userRolesResultMap is right there
above the select Sql, and it delares the type to be User, so how can
it not find it?
If anyone has a single example, with the java beans, DB table
structure and mapper xml I would be very very greatful.