Echo
Echo

Reputation: 3029

Fetch Map<String,CustomData> from IBatis

I am creating an ibatis quesry that its result should be :

Map<String,CustomData>

My ibatis query:

<resultMap id="dataMap" class="java.util.HashMap">
    <result property="key" column="UUID"/>
    <result property="value" resultMap ="customData"/>
</resultMap>

<resultMap id="customData" class="com.model.CustomData">
    <result property="x" column="X_COL"/>

</resultMap>

<select id="fetchData"
        resultClass="java.util.HashMap"
        parameterClass="java.util.Map">
   SELECT
    UUID AS UUID,
    (CASE
    WHEN SOME_DATA IS NOT NULL THEN  'TRUE'         
    END) AS X_COL
    FROM TABLE
 </select>

CustomData is a java class:

public class CustomData{
 private String x;

//Getters & Setters

}

I expect to get the following on the Java:

Map<String,CustomData>

However I get the following:

Map<String,String>

Any ideas !

Upvotes: 1

Views: 11598

Answers (1)

zoom
zoom

Reputation: 1756

You should try to replace the resultClass attribute in your select tag by a resultMap with a "dataMap" value like this :

<select id="fetchData"
    resultMap="dataMap"
    parameterClass="java.util.Map">
<!-- your query -->
</select>

In your case the queryForList method try to instanciate a java.util.HashMap instead of this, it should use the dataMap mapping you defined above.

Upvotes: 3

Related Questions