ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alin Popa <alin.p...@gmail.com>
Subject Re: String list in resultMap
Date Thu, 11 Jun 2009 05:36:05 GMT
Hi,

I suggest doing something like that (this example was not tested):

<sqlMap namespace="MyNamespace">

   <resultMap id="result" class="your.pack.Attribute">
      <result property="name" column="name_column" columnIndex="1"/>
      <result property="values" resultMap="MyNamespace.resultValues"/>
   </resultMap>

   <resultMap class="java.lang.String" id="resultValues">
      <result property="" column="your_column"/>
   </resultMap>

</sqlMap>

On Wed, Jun 10, 2009 at 9:06 PM, cbchhaya <cbchhaya@gmail.com> wrote:

>
> Unfortunately that doesn't work either.
>
> The question in really simple terms:
>
> What should be the result map for this class:
>
> class Attribute {
>    String name;
>    List<String> values;
> }
>
>
>
> cbchhaya wrote:
> >
> > Almost, except that I am already using a result-mapping to get all
> > attributes for an object, and every attribute has a bunch of fields, one
> > of which is a list of strings. Having already selected all the required
> > data, I am just looking for a way to bunch up the 'attrValue' field into
> a
> > list of strings. Perhaps I should group by every other property of the
> > attribute?
> >
> >
> >
> > Gwyn wrote:
> >>
> >> I'm not 100% sure, but it looks to me as if this is the subject of the
> >> "Result Maps"/"Complex Collection Properties" section of the
> >> "Developer Guide" document.
> >>
> >> On Wed, Jun 10, 2009 at 3:59 AM, cbchhaya<cbchhaya@gmail.com> wrote:
> >>>
> >>> I have the following classes:
> >>> class Attribute {
> >>>    String attrName;
> >>>    List<String> values;
> >>> }
> >>>
> >>> and
> >>>
> >>> class DomainObj {
> >>>    String objName;
> >>>    String objType;
> >>>    List<Attribute> attrs;
> >>> }
> >>>
> >>> I have a database table that stores <objId, objName, objType>, another
> >>> one
> >>> that stores <attrId, attrName> and another one that stores <objId,
> >>> attrId,
> >>> attrValue> so that there are multiple rows in the final table if the
> >>> attribute is multi-valued.
> >>>
> >>> A simple select returns objName, objType, attrName, attrValue but my
> >>> problem
> >>> is mapping the attrValue to a java list in the resultMap
> >>>
> >>> <resultMap id="..." class="DomainObj" groupBy="objName, objType>
> >>>    <result property="objName" column="objName" />
> >>>    ....
> >>>    <result property="attrs" resultMap="attr-result" />
> >>> </resultMap>
> >>>
> >>> <resultMap id="attr-result" class=Attribute" groupBy="attrName">
> >>>    <result property="attrName" column="attrName" />
> >>>    <result property="values" ....? />
> >>> </resultMap>
> >>>
> >>> How do I go about mapping the 'values' property in Attribute (which is
> a
> >>> List of Strings). I tried specifying the class for the result as List
> >>> but it
> >>> doesn't work and I didn't expect it to either.
> >>>
> >>> What is the right way of doing this? Am I overlooking something basic
> >>> here?
> >>>
> >>> Thanks!
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/String-list-in-resultMap-tp23954863p23954863.html
> >>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >>>
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/String-list-in-resultMap-tp23954863p23967886.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>


-- 
Regards,

Alin

Mime
View raw message