Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mybatis resultmap to map values to hash map field of a model

Tags:

java

mybatis

I am trying to map create a result map that will populate vehicleVO. I want to map few columns to vehicleDocuments HashMap. I am having the data to be populated also present in the same table.

public class VehicleVO implements Serializable {
    public String vehicleId;
    public String vehicleNumber;
    public String model;
    public Map<String, Date> vehicleDocuments;
    public TransportVO transport;
    public String distanceTraveled;

}

I am trying to use the following xml for mapping. But it don't seem to work. I a gettign this error

"The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".

<resultMap id="BaseResultMap" type="com.svms.service.vo.VehicleVO">
        <id column="vehicle_id" jdbcType="BIGINT" property="vehicleId" />
        <result column="vehicle_no" jdbcType="VARCHAR" property="vehicleNumber" />
        <result column="Model" jdbcType="VARCHAR" property="model" />
        <association property="vehicleDocuments" javaType="java.util.HashMap">
            <result column="FC" jdbcType="DATE" property="FC_TD" />
            <result column="TAX" jdbcType="DATE" property="TAX_TD" />
            <result column="Insureance" jdbcType="DATE" property="INSURANCE_TD" />
            <result column="Form47" jdbcType="DATE" property="FORM47_TD" />
            <result column="NC" jdbcType="DATE" property="NC_TD" />
        </association>
        <result column="total_distance" jdbcType="INTEGER" property="distanceTraveled" />
        <result column="transport_id" jdbcType="BIGINT" property="transportId" />
</resultMap>

If my understanding is correct, Trying to map to an hashMap can also be considered as association mapping. But this is a one to one mapping only. I also tried using the <collection> tag for mapping. Still I get the same error.

like image 709
om39a Avatar asked Dec 18 '25 07:12

om39a


1 Answers

The order of elements under 'resultMap' should be maintained as dictated by the DTD. Move all the 'result' tags to appear before the 'association' tag.

like image 180
Seeta Somagani Avatar answered Dec 19 '25 23:12

Seeta Somagani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!