incorrect mapping of results

50 views
Skip to first unread message

Danny Stommen

unread,
Oct 11, 2011, 9:26:05 AM10/11/11
to mybatisnet-user
Hi All,

I'm completely lost with a problem. I'm trying to select data
dynamically. To do this, I've a List<string> containing the columns I
want to select, which I pass into the sql statement and use the
iterate tag to populate this in the sql statment.

This looks like:
SELECT
<iterate property="columns" conjunction="," open="" close="">
$columns[]$
</iterate>
FROM my_table
WHERE ...


My table contains the following columns (simplified): AdvertiserId,
Impression, Clicks (all integer)

When I populate the List I'm passing in with the first 2 columns, it
works fine. When I restart my program en add all 3 columns, it still
works fine.

But, if I run the query with the first 2 columns, add the last column
to the list en re-run the qeury again (without restarting), the
results are not mapped correctly. The strange thing is that the
results of Clicks are mapped to Impressions, and Clicks is always 0.

I'm using ResultClass="MyObject", because of the dynamic result I
can't use a ResultMap. Any idea what could be causing this? I don't
use any caching.

Another strange thing, when I change the ResultClass to Hashtable, I
can see that all correct property names have the correct values...

Michael McCurrey

unread,
Oct 11, 2011, 9:45:12 AM10/11/11
to mybatis...@googlegroups.com
Are you using a ResultMap?  As of right now if you use a ResultMap and you have that third column mapped but it isn't in your Select Statement, it will fail.

Danny Stommen

unread,
Oct 12, 2011, 4:56:17 AM10/12/11
to mybatisnet-user
No, as metioned in my first post, I'm using ResultClass because I
don't know in advance which column are requested.

I simplified my explanation to 3 columns, but the actual table is
containing 12 columns. Because this is a rather large reporting table,
I want to prevent that each time all columns are retrieved.

Michael McCurrey

unread,
Oct 12, 2011, 8:15:33 AM10/12/11
to mybatis...@googlegroups.com
Interesting, can you post an example of it failing?  Either your SqlMap & Class or a failing test?

Danny Stommen

unread,
Oct 12, 2011, 9:07:23 AM10/12/11
to mybatis...@googlegroups.com
The sql map looks like this

    <select id="Select" resultClass="Network" parameterClass="Hashtable">
      SELECT
        <iterate property="columns" conjunction="," open="" close="">
            $columns[]$
        </iterate>
      FROM rep_network_daily
      WHERE        
        MemberId = #memberId#
        AND ner_Date BETWEEN #startDate# AND #endDate#
      <isNotEmpty property="groupBy" prepend="GROUP BY">
        <iterate property="groupBy" conjunction="," open="" close="">
          $groupBy[]$ 
        </iterate>
      </isNotEmpty>
    </select>

The Network.cs is attached. 
Network.cs

Danny Stommen

unread,
Oct 17, 2011, 8:23:23 AM10/17/11
to mybatisnet-user
Hi Micheal,

Did you have any chance to take a look at the problem?

Thanks,
Danny

On Oct 12, 3:07 pm, Danny Stommen <da...@bannerconnect.net> wrote:
> The sql map looks like this
>
>     <select id="Select" resultClass="Network" parameterClass="Hashtable">
>       SELECT
>         <iterate property="columns" conjunction="," open="" close="">
>             $columns[]$
>         </iterate>
>       FROM rep_network_daily
>       WHERE
>         MemberId = #memberId#
>         AND ner_Date BETWEEN #startDate# AND #endDate#
>       <isNotEmpty property="groupBy" prepend="GROUP BY">
>         <iterate property="groupBy" conjunction="," open="" close="">
>           $groupBy[]$
>         </iterate>
>       </isNotEmpty>
>     </select>
>
> The Network.cs is attached.
>
>  Network.cs
> 4KViewDownload

Danny Stommen

unread,
Nov 2, 2011, 7:49:36 AM11/2/11
to mybatisnet-user
No one any idea?
Reply all
Reply to author
Forward
0 new messages