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 jaybytez <ja...@gmail.com> on 2006/06/21 17:11:42 UTC

Return result as Map

I maybe misunderstanding queryForMap which seems to return a Map that
contains a key you specify and a full object or result in the value.  What I
am looking to do is actually return a Map from a query that places a key and
value in a Map (key being = to one column) and (value being = to another
column).  I have the following query:

  <select id="selectFacilityServiceLookup" resultClass="java.util.Map">
    <![CDATA[
      SELECT facility_service_desc, facility_service_code
      FROM facility_service_lookup
    ]]>
  </select>

I would like a Map that contains a row for each record and the key for the
map to be facility_service_desc and the value for the map to be
facility_service_code.  I am calling this template using the queryForMap
with the Object = null, and the key = facility_service_desc, and the value =
facility_service_code.

Can this be done?  Am I calling them incorrectly?

Thanks,

jay blanton
--
View this message in context: http://www.nabble.com/Return-result-as-Map-t1824496.html#a4976185
Sent from the iBATIS - User - Java forum at Nabble.com.


RE: Return result as Map

Posted by jaybytez <ja...@gmail.com>.
Here is my query:

  <select id="queryMapFacilityServiceLookup"
resultClass="java.util.HashMap">
    <![CDATA[
      SELECT facility_service_desc, facility_service_code
      FROM facility_service_lookup
    ]]>
  </select> 

And here is how I call it:

Map mappedValues =  sqlMap.queryForMap("queryMapFacilityServiceLookup",
null, "facility_service_desc","facility_service_code");

And i get a Map back with null values and one row.
--
View this message in context: http://www.nabble.com/Return-result-as-Map-t1824496.html#a4983369
Sent from the iBATIS - User - Java forum at Nabble.com.


RE: Return result as Map

Posted by jaybytez <ja...@gmail.com>.
This is probably what happened.  I rewrote this section to not use a
Map...but it maybe possible I did not write the properties correctly since I
am new to this.  I will reverify...but I am pretty sure when I ran it that I
got no results back.
--
View this message in context: http://www.nabble.com/Return-result-as-Map-t1824496.html#a4983120
Sent from the iBATIS - User - Java forum at Nabble.com.


Re: Return result as Map

Posted by Debasish Dutta Roy <de...@gmail.com>.
Map will work.

1. You have to mention as java.util.HashMap as has been mentioned by Niels.
Here point to be noted if you do not give a concrete class then iBATIS does
not know what to instantiate and should give exception, I have received this
exception. So I suspect there is something else that is wrong before this
piece of code is executed.

2. Your java code mention which one you want as key and which one as a
value.

e.g. sqlMap.queryForMap("selectFacilityServiceLookup", null,
"facility_service_code", "facility_service_desc");

It simply has to work, I use this everyday.

On 6/21/06, jaybytez <ja...@gmail.com> wrote:
>
>
> It did not work and I received no exceptions.  It just returned no
> results.
>
> Therefore, I switched my code and created a simple TO that had only the
> two
> fields in it.  And then had to create a search mechanism on the TO since
> it
> does not have the Map lookup capabilities to find the value of a key.
>
> Thanks,
>
> -jay
> --
> View this message in context:
> http://www.nabble.com/Return-result-as-Map-t1824496.html#a4980225
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>

RE: Return result as Map

Posted by jaybytez <ja...@gmail.com>.
It did not work and I received no exceptions.  It just returned no results.

Therefore, I switched my code and created a simple TO that had only the two
fields in it.  And then had to create a search mechanism on the TO since it
does not have the Map lookup capabilities to find the value of a key.

Thanks,

-jay
--
View this message in context: http://www.nabble.com/Return-result-as-Map-t1824496.html#a4980225
Sent from the iBATIS - User - Java forum at Nabble.com.