You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Andrew Bethell (JIRA)" <ib...@incubator.apache.org> on 2006/10/05 11:55:46 UTC

[jira] Created: (IBATIS-352) Problems with Complex Properties + Sets & enums

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 2.2.0.638, Spring 2.0
            Reporter: Andrew Bethell
         Attachments: 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

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Paul Benedict (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12462127 ] 

Paul Benedict commented on IBATIS-352:
--------------------------------------

I actually solved the problem, but it is totally not obvious :-) 

<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: https://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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt, sqlmap.zip
>
>
> 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: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Jeff Butler (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-352?page=comments#action_12454417 ] 
            
Jeff Butler commented on IBATIS-352:
------------------------------------

Would you try this again with the latest iBATIS source code from SVN?  There was a problem in the UnknownTypeHandler related to enums - I'm wondering if your issue may be resolved now.

> 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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt, sqlmap.zip
>
>
> 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

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Andrew Bethell (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-352?page=comments#action_12441427 ] 
            
Andrew Bethell commented on IBATIS-352:
---------------------------------------

I apologise for the poor description of my problem, hopefully I can give a clearer overview of the problem this time.

I have a custom Type Handler that converts VARCHAR values ('ACT' , 'DEL', 'DIS'... ) to Enum types (Active / Deleted / Disabled ..).  I followed the guide on the Ibatis Wiki that explains how to use custom type handlers with java 5 enums - and everything worked fine initially, but after I completed mapping my objects I started getting bulkbean exceptions.

I think I have isolated the problem to when custom typehandlers are applied to the items of collection-complex properties, that are loaded with joins & resultMaps. 

When selecting data-  populating a single complex property which uses a custom type handler works fine, when lazy loading and using joins + nested property mappings.  

However, when populating a complex property which is a collection (tried Set and List), and the resultMap for that collection has a custom property - a bulkbeanexception is thrown (join-resultmap with enum.txt).  - eg

(from my Article.xml)
<resultMap id="articleResult" class="org.andy.sandbox.domain.Article" groupBy="id">
...
<result property="resources" javaType="java.util.TreeSet" resultMap="Resource.resourceResult"/>
..
</resultMap>

In this example - resourceResult contains a property which uses a custom type handler.  This happens when I declare a typehandler in my sqlMapConfig - ie

    <typeHandler javaType="org.andy.sandbox.domain.RecordStatus"
                 callback="org.andy.sandbox.dao.RecordTypeHandler"/>

and also when specifying a typehandler for a specific property - - in this case I am just mapping to a value of type boolean

<result property="statuss" column="RESOURCE_REC_STATUS" typeHandler="org.andy.sandbox.dao.TestTypeHandler"/>-

If I remove the mappings for these properties, my selects work fine.

The same problem does not occur when lazy-loading a collection of items which have custom-type properties - ie 

(from my Issue.xml)
<resultMap id="issueResult" class="org.andy.sandbox.domain.Issue" groupBy="id">
...
<result property="articles" column="ISSUE_ID" select="Article.getArticlesByIssue"/>
...
</resultMap>


> 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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: 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

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Andrew Bethell (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-352?page=comments#action_12458186 ] 
            
Andrew Bethell commented on IBATIS-352:
---------------------------------------

I have tried with the latest 2.3 beta (1st december) and I still have the same errors.

> 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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt, sqlmap.zip
>
>
> 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

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Jeff Butler (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-352?page=comments#action_12440152 ] 
            
Jeff Butler commented on IBATIS-352:
------------------------------------

If I understand correctly, you are trying to report three different issues:

1. Something changed regarding Lists in iBATIS 2.2.0 that forced you to use Sets

2. Lazy load of Sets doesn't work

3. Sets work except when there are enums

This is very confusing.  Please attach your SqlMap.xml for each different issue.


> 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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: 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

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Andrew Bethell (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12464163 ] 

Andrew Bethell commented on IBATIS-352:
---------------------------------------

Unfortunately I think my problem is slightly different to Paul's:

Article
   - long id
   - String headline
   - String text
    - Set<Resource>  resources 

Resource
  - long id
  - byte[] data
  - String name
  - RecordStatus status   <-- enum type that fails to map

The problem occurs when maping the enum type within my 'Resource'  object, when querying for an article (or list of articles).  

I have a hack to work around this, mapping the column value to a String property (instead of the enum type), then overriding the 'status'  get/setters- converting the String property (which stores the column property) back into the enum and visa versa.

> Problems with Complex Properties + Sets & enums
> -----------------------------------------------
>
>                 Key: IBATIS-352
>                 URL: https://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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt, sqlmap.zip
>
>
> 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: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Paul Benedict (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-352?page=comments#action_12461118 ] 
            
Paul Benedict commented on IBATIS-352:
--------------------------------------

I believe I have the same problem as Andrew. However, it doesn't seem related to Sets, but any kind of collection that is in itself an Enum:

I wrote a query which returns a user and its associated roles. The resultMap looks like this:

<resultMap id="userMap" class="User" groupBy="id">
  <result property="id" column="u_id" />
  <result property="roles" column="ur_id" />
</resultMap>

As you can see, I am grouping by "id" which means I should be collecting all my roles in property "roles" which is a List<Role>. I already have a type handler setup to translate the long into the enum/class, but it's not working.

While I am using Java 5, this problem is not (I don't think) a Java 5 problem. I've seen many examples of using the @resultMap attribute on a collection to construct the objects to avoid N+1 selects. But what about just plain old Java types or enums?

> 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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt, sqlmap.zip
>
>
> 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

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Donovan Frew (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12462324 ] 

Donovan Frew commented on IBATIS-352:
-------------------------------------

Thanks Paul.  I tried your solution and it worked like a charm.  I had figured that I was approaching it incorrectly.  I guess these discussions will help to improve the documentation.

> Problems with Complex Properties + Sets & enums
> -----------------------------------------------
>
>                 Key: IBATIS-352
>                 URL: https://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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt, sqlmap.zip
>
>
> 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: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (IBATIS-352) Problems with Complex Properties + Sets & enums

Posted by "Donovan Frew (JIRA)" <ib...@incubator.apache.org>.
    [ 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>

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

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

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 2.2.0.638, Spring 2.0
>            Reporter: Andrew Bethell
>         Attachments: domain.zip, join-resultmap with enum.txt, lazy-load with set.txt, sqlmap.zip
>
>
> 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