ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikael Andersson" <mail.mi...@gmail.com>
Subject Re: Mapping reuslt to to java.util.Map with dynamic key(from column), possible?
Date Thu, 05 Apr 2007 21:24:05 GMT
Hi

Pretty cool feature which I didn't know about :), thanks for the tip.

Could you give an example how the queryForMap feature can be used with a
nested resultMap, googled a bit and only found how to use it to populate a
Map instead of a List as the result of calling a select from the DAO.

Thanks,
 Mike

On 05/04/07, Daniel Pitts <Daniel.Pitts@cnet.com> wrote:
>
>  I think its called queryForMap :-)
>
>  ------------------------------
> *From:* Mikael Andersson [mailto:mail.micke@gmail.com]
> *Sent:* Thursday, April 05, 2007 6:28 AM
> *To:* user-java@ibatis.apache.org
> *Subject:* Mapping reuslt to to java.util.Map with dynamic key(from
> column), possible?
>
> Hi
>
> I wonder if it is possible to populate a Map via a resultMap so that the
> key is the value from a column and the value the value of another column?
>
> I read how about to create a Map with pre specified key values in the PDF
> documentation, but I couldn't find how to use dynamic key value.
>
> public class MyVO{
> private int id;
> private Map<String,String> properties;
>
> // getters and setters ...
> }
>
> Table design :
> ID | type | value |
> ------------------------
> 1  | xx    | val1   |
> 1  | xy    | val2   |
> 1  | yx    | val3   |
> 1  | yy    | val4   |
>
> <resultMap class="MyVO" id="map1">
> <result property="id" column="ID"/>
> <result property="properties" resultMap="map2"/>
> </resultMap>
>
> <resultMap class="java.util.Map" id="map2">
> ?????
> </resultMap>
>
> With the above table data I would like to have one MyVO object with a map
> containing the following (type column dictates map key):
> [
> key="xx" value="val1"
> key="xy" value="val2"
> key="yx" value="val3"
> key="yy" value="val4"
> ]
>
> Cheers,
>  Mike
>
>

Mime
View raw message