You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by cbchhaya <cb...@gmail.com> on 2009/06/10 04:59:27 UTC

String list in resultMap

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.


Resolved: String list in resultMap

Posted by cbchhaya <cb...@gmail.com>.
<resultMap id=”attr-result” class=”Attribute”>
	<result property=”attrName” column=”…” />
	<result property=”values” resultMap=”attr-vals” />	<!—No need to specify
type List here -->
</resultMap>

<resultMap id=”attr-vals” class=”java.lang.String”>
	<result property=”val” column=”VALUE” /> <!—val could be called anything,
haven’t tried leaving it blank -->
</resultMap>

Hope this helps someone!

-- 
View this message in context: http://www.nabble.com/String-list-in-resultMap-tp23954863p23968718.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: String list in resultMap

Posted by Alin Popa <al...@gmail.com>.
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 <cb...@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<cb...@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

Re: String list in resultMap

Posted by cbchhaya <cb...@gmail.com>.
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<cb...@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.


Re: String list in resultMap

Posted by cbchhaya <cb...@gmail.com>.
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<cb...@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-tp23954863p23962385.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: String list in resultMap

Posted by Gwyn Evans <gw...@gmail.com>.
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<cb...@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.
>
>