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 c....@ads.it on 2006/12/01 14:37:30 UTC

Re: Return result as Map



The issue has been solved by using the cast to java.math.BigDecimal

        lResult = (Map<BigDecimal, BigDecimal>) lSqlMapClient.queryForMap(
"selectTipiOrizzontali", null, "TIPO_DATO_ID", "TIPO_TABELLA_ID" );

Using cast is always a point of discontinuity in the type cheking...

ciao



                                                                           
             c.zecca@ads.it                                                
                                                                           
             30/11/2006 13:53                                          Per 
                                       user-java@ibatis.apache.org         
                                                                        CC 
                Per favore,                                                
               rispondere a                                        Oggetto 
             user-java@ibatis.         Re: Return result as Map            
                apache.org                                                 
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Debasish Dutta Roy wrote
http://www.mail-archive.com/user-java@ibatis.apache.org/msg04713.html

> Wed, 21 Jun 2006 12:32:25 -0700
>
> 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.

It works!
Well. here is a similar case: I have to retrieve two columns a-la key -
value
The type of both the involved columns is NUMBER(10)
Here is the map

<select id="selectTipiOrizzontali" resultClass="java.util.HashMap">
select
TIPO_DATO_ID,
TIPO_TABELLA_ID
from TIPI_DATO
where FORMATO = 'T'
</select>

The query extracts the teo columns for the 24 rows currently stored in the
table.
This is the Java code that exerts the "selectTipiOrizzontali"

        lResult = (Map<Integer, Integer>) lSqlMapClient.queryForMap(
"selectTipiOrizzontali", null, "TIPO_DATO_ID", "TIPO_TABELLA_ID" );

Well, the first use to the iterator Iterator<Integer> on the keySet()

Integer lInteger = lIter.next();

raises the java.lang.ClassCastException: java.math.BigDecimal exception.

Inspection with the debugger confirms that the Map contains 24 pairs
but.... the types are BigDecimal BigDecimal (instead of the expected
Integer). That makes sense because the colums are declared of NUMERIC type.

Is there any way, in the SQL map, to state that the types of "TIPO_DATO_ID"
and should be considered as javaType="java.lang.Integer"?

Regard