ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Donovan Frew (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums
Date Mon, 01 Jan 2007 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"/>

    <select id="get-resource" resultMap="resource" parameterClass="long">
        select ID, NAME from USERS where ID = #value#

    <select id="get-resource-roles" resultClass="int">
        select ROLES_ID from USER_ROLES where USER_ID = #value#

This didn't fail, but neither did it work as expected.  The roles Set was populated but with
objects of type Integer,  which of course broke all my tests.

Anyway, maybe some instructions on how best to use Enum Collections would help to clear up
this issue.  I know my TypeHandler works because everything works as expected when I use Role
as a simple property.

> Problems with Complex Properties + Sets & enums
> -----------------------------------------------
>                 Key: IBATIS-352
>                 URL: http://issues.apache.org/jira/browse/IBATIS-352
>             Project: iBatis for Java
>          Issue Type: Bug
>          Components: SQL Maps
>    Affects Versions: 2.2.0
>         Environment: JDK 1.5, IBATIS SQL Maps, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt,
> There doesnt seem to be support for lazy-loading complex properties of type 'java.util.Set',
only List collections -  (stack trace attached to this issue).
> I have to use Set collections at the moment, as when I upgraded from IBATIS SQLMaps 2.17
to 2.22, the 'groupBy' attribute for resultmaps did not seem to make data in (List) complex
properties distinct by ID, where as in version 2.17 this was the case.
> Strangely though, when loading complex properties with joins+resultMaps, Set properties
work correctly - except when items in the Set contain enum types (stack trace attached for
this too).

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message