I see this issue very strange descibed on google or stack. Let me explain.
I have Result Maps in annotations in my interface method. Only in this particular case I need dynamic query, and that is the reason I decided to write the whole mapper for interface in xml file. Below I paste the whole file. The select query should be ok, but I am occuring some difficulties with <resultMap>
.
On the different websides I was searching for a good explanation of one to one, one to many, many to one association and construct of this result map in general.
I saw there is some kind of possibility to part it into subqueries, subresultmaps. But I have that already done with myBatis annotations, and I want to use it.
Could you direct me, how should the resultMap be constructed? I dont see need for constructor, discriminator, but it is still shouting... (that is why I added <collection>
mark) - IntelliJ is underscoring the whole <resultMap>
saying: "The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)"
I know it seems obvious, but I have completly no idea how to do it correctly. Please help me.
xml mapper file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pl.net.manager.dao.UsageCounterDAO">
<select id="getUsageCounterList" resultType="pl.net.manager.domain.UsageCounter"
resultMap="getUsageCounterListMap">
SELECT * FROM usage_counter WHERE
<if test="apiConsumerIdsList != null">
api_consumer IN
<foreach item="item" index="index" collection="apiConsumerIdsList"
open="(" separator="," close=")">
#{item}
</foreach>
AND
</if>
<if test="serviceConsumerIdsList != null">
service IN
<foreach item="item" index="index" collection="serviceConsumerIdsList"
open="(" separator="," close=")">
#{item}
</foreach>
AND
</if>
<if test="dateFrom != null">
date >= #{dateFrom} AND
</if>
<if test="dateTo != null">
date <= #{dateTo} AND
</if>
<if test="status != null">
status = #{status}
</if>
</select>
<resultMap id="getUsageCounterListMap" type="">
ofType="pl.net.manager.domain.UsageCounter">
<id property="id" column="id"/>
<result property="date" column="date"/>
<result property="apiConsumer" column="api_consumer"
javaType="pl.net.manager.domain.ApiConsumer"/>
<association property="apiConsumer" column="api_consumer"
resultMap="pl.net.manager.dao.ApiConsumerDAO.getApiConsumer"/>
<result property="service" column="service" javaType="pl.net.manager.domain.Service"/>
<association property="service" column="service"
resultMap="pl.net.manager.dao.ServiceDAO.getService"/>
<result property="counterStatus" column="counter_status"/>
<result property="ratingProcessId" column="rating_process_id"/>
<result property="value" column="value"/>
<result property="createdDate" column="created_date"/>
<result property="modifiedDate" column="modified_date"/>
</resultMap>
</mapper>