ResultMap collection create more than one item for the collection in each row returned by db.

133 views
Skip to first unread message

Justin Phillips

unread,
Sep 6, 2012, 1:10:14 PM9/6/12
to mybati...@googlegroups.com
Hi all,
I'm trying to map a result into a list of pojos but having some trouble...

301 09:59:01,174 DEBUG ResultSet:27 - <==    Columns: nodeid, nodeenergy, vid, energy, vid, energy
302 09:59:01,176 DEBUG ResultSet:27 - <==        Row: 00:D0:69:41:F6:77.1, 37845.971, 1, 94895.68, 2, 94895.68
303 09:59:01,178 DEBUG ResultSet:27 - <==        Row: 00:D0:69:41:F6:8C.1, 57049.709, 1, 94895.68, 2, 94895.68

in my resultset you can see that i have two columns named vid and energy.
i want those to map into this

    <resultMap id="result" type="VerticaQueryResult">
        <result property="nodeenergy" column="nodeenergy"/>
        <result property="nodeid" column="nodeid"/>
        <collection property="vEnergy" resultMap="vidEnergy" ofType="VidEnergy"/>
    </resultMap>
    
    <resultMap id="vidEnergy" type="VidEnergy">
        <result property="vid" column="vid"/>
        <result property="energy" column="energy"/>
    </resultMap>

but when i run it i only ever get one item in my list once mybatis is done doing it's magic.
any advice?
thank you

Jeff Butler

unread,
Sep 6, 2012, 3:06:35 PM9/6/12
to mybati...@googlegroups.com
If there are two normalized tables and this result set comes from a
join, then a better solution is to write a simple join so MyBatis can
do it for you automatically. The result set should look like this:

nodeid, nodeenergy, vid, energy
00:D0:69:41:F6:77.1, 37845.971, 1, 94895.68
00:D0:69:41:F6:77.1, 37845.971, 2, 94895.68
00:D0:69:41:F6:8C.1, 57049.709, 1, 94895.68
00:D0:69:41:F6:8C.1, 57049.709, 2, 94895.68

If there is only one table with repeated columns, then you have to do
it with a row handler - but that might be bad database design.

Jeff Butler
Reply all
Reply to author
Forward
0 new messages