1 Jan 2007 21:54
Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums
Donovan Frew (JIRA <ibatis-dev <at> incubator.apache.org>
2007-01-01 20:54:27 GMT
2007-01-01 20:54:27 GMT
[
http://issues.apache.org/jira/browse/IBATIS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12461643
]
Donovan Frew commented on IBATIS-352:
-------------------------------------
I too am having the same issue as Paul and Andrew, however I believe that part of my problem is related to the
fact that I am not sure how to specify my result map for a Set of Enums.
The documentation on complex collection properties to avoid N+1 selects seems to only apply to javabeans
(as they can be instantiated as opposed to Enum types which cannot). I therefore opted to use the other
option and came up with this :
public class User {
private int id;
private String name;
private Set<Role> roles; // Role is an Enum type
// assume appropriate getters and setters
}
// -----------------
<resultMap id="user-result" class="User">
<result property="id" column="ID"/>
<result property="name" column="NAME"/>
<result property="roles" column="ID" select="get-resource-roles" typeHandler="com.ackee.herring.dao.ibatis.RoleTypeHandlerCallback"/>
</resultMap>
(Continue reading)
<typeHandler javaType="org.xyz.Role" ... />
<resultMap id="userMap" class="User" groupBy="id">
<result property="id" column="u_id" />
<result property="roles" resultMap="NameSpace.roleResult"
</resultMap>
<resultMap id="roleResult" class="Role">
<result property="value" column="ur_id" />
</resultMap>
It turns out when there is a result map with just one item in it, and you provide a type handler, Ibatis will
treat it "like" a primitive type -- the first result is the value. Who would have thought!!
This is really not obvious at all. I recommend IBATIS adds a resultClass to the <result> tag so that users
don't need yet another map to translate single values (enums and primitives in collections especially).
Hence this would become:
<resultMap id="userMap" class="User" groupBy="id">
<result property="id" column="u_id" />
<result property="roles" column="ur_id" resultClass="Role" />
</resultMap>
> Problems with Complex Properties + Sets & enums
> -----------------------------------------------
>
> Key: IBATIS-352
> URL:
RSS Feed