Reputation: 1406
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.
Upvotes: 2
Views: 14477
Reputation: 8949
You'll need to implement a ResultHandler to build a Hashmap unfortunately.
Also, the DTD error you mention is because the result elements must be before the association elements.
Upvotes: 1
Reputation: 787
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.
Upvotes: 16