[
https://issues.apache.org/jira/browse/IBATIS-521?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12701450#action_12701450
]
Kengkaj Sathianpantarit commented on IBATIS-521:
------------------------------------------------
I'm not sure if this is a bug. You don't specify groupBy in
searchPersonResultMap so iBATIS maps all records into list of
mydomain.grpart.test.groupby.SearchResult, grouping in personResultMap is too
late.
Specifying groupBy in a resultMap should mean group that resultMap by a
specified property, doesn't it?
> groupby works only in top level result map
> ------------------------------------------
>
> Key: IBATIS-521
> URL: https://issues.apache.org/jira/browse/IBATIS-521
> Project: iBatis for Java
> Issue Type: Bug
> Components: SQL Maps
> Affects Versions: 2.3.2
> Environment: JRE 1.5.0_12 on Windows 2000
> Reporter: Reto Welti
>
> It seems to be that a groupby must be defined on the top level resultmap,
> because I've got the following problem:
> For this example I have store some search results in a table and would like
> to load these search results to my java program. The table looks like this:
> MATCH NAME FIRSTNAME INTERNATIONALAREACODE NETWORKGROUP PHONENUMBER
>
> ---------------------------------------------------------------------------------------------------------------------------------------------
> ------------------------------
> 100 Meier Hans 41 44 710 05 05
> 100 Senderos Mark 41 78 745 45 45
> 83 Eichenberger Heinrich 41 41 745 45 65
> 83 Eichenberger Heinrich 41 79 505 12 46
> 75 Müller Franz 41 58 712 13 15
> My beans looks like this:
> public class SearchResult {
> /** agreement of the search parameters (in percentage) */
> private Integer match;
> /** located person */
> private Person person;
> (...)
> }
> public class Person {
> private String name;
> private String firstName;
> private List<PhoneNumber> phoneNumbers;
> (...)
> }
> public class PhoneNumber {
> /** regional prefix or network group */
> private Integer networkGroup;
> /** country prefix for international connections */
> private Integer internationalAreaCode;
> /** phone number */
> private String phoneNumber;
> (...)
> }
> Here is the sql statement I would like to access the data and the related
> result maps:
> <select id="searchPerson" resultMap="searchPersonResultMap">
> select match, name, firstname, internationalareacode,
> networkgroup, phonenumber
> from mysearchresults
> order by match desc
> </select>
> <resultMap id="searchPersonResultMap"
> class="mydomain.grpart.test.groupby.SearchResult">
> <result property="match" column="match"/>
> <result property="person" resultMap="Test.personResultMap"/>
> </resultMap>
>
> <resultMap id="personResultMap" class="mydomain.grpart.test.groupby.Person"
> groupBy="name">
> <result property="name" column="name"/>
> <result property="firstName" column="firstname"/>
> <result property="phoneNumbers" resultMap="Test.phoneNumbersResultMap"/>
> </resultMap>
>
> <resultMap id="phoneNumbersResultMap"
> class="mydomain.grpart.test.groupby.PhoneNumber">
> <result property="internationalAreaCode" column="internationalareacode"/>
> <result property="networkGroup" column="networkgroup"/>
> <result property="phoneNumber" column="phonenumber"/>
> </resultMap>
> Now I access the data in my program and print out the objects. This is my
> output:
> --------------------------------------------------------------------
> Match: 100%
> Name: Meier Firstname: Hans
> Number of Phones: 1
> --------------------------------------------------------------------
> Match: 100%
> Name: Senderos Firstname: Mark
> Number of Phones: 1
> --------------------------------------------------------------------
> Match: 83%
> Name: Eichenberger Firstname: Heinrich
> Number of Phones: 2
> --------------------------------------------------------------------
> Match: 83%
> person is null!!!
> --------------------------------------------------------------------
> Match: 75%
> Name: Müller Firstname: Franz
> Number of Phones: 1
> --------------------------------------------------------------------
> You see, that the third result was correct filled, Mr. Eichenberger has two
> phone numbers. But the fourth result has a match, but no person. This entry
> is needless.
> If I am getting only a person out of this table with the same result maps,
> everthing works correct. This is my statement:
> <select id="getPerson" resultMap="personResultMap">
> select match, name, firstname, internationalareacode,
> networkgroup, phonenumber
> from mysearchresults
> where name = #name#
> </select>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.