Reputation: 163
I'm following the example in the MyBatis website to create a mapper that has a nested collection, when I do a select operation my object (Provider) is return but the collection inside it (ProviderParameter) is empty, when I go to the database tool and apply the same query I get the expected result (the collection is return too).
Here is my mapper:
<resultMap id="Provider" type="xxx.Provider">
<result column="idProvider" property="idProvider"/>
<result column="providerType" property="providerType"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="licenceInformation" property="licenseInformation"/>
<collection property="parameters" ofType="xxx.ProviderParameter">
<result column="idProviderParameter" property="idProviderParameter"/>
<result column="name" property="name"/>
<result column="value" property="value"/>
</collection>
</resultMap>
And the select:
<select id="getProviderById" resultType="xxx.Provider">
select P.idProvider as idProvider
,P.providerType as providerType
,P.username as username
,P.password as password
,P.licenceInformation as licenceInformation
,PP.idProviderParameter as idProviderParameter
,PP.name as name
,PP.value as value
from [dbo].[msg_Provider] AS P
left outer join [dbo].[msg_ProviderParameter] AS PP on P.idProvider = PP.idProvider
where P.idProvider = #{idProvider}
</select>
Upvotes: 0
Views: 1279
Reputation: 163
My problem was that in the select I put resultType instead of resultMap,
So the select should be like:
<select id="getProviderById" resultMap="Provider">
select P.idProvider as idProvider
,P.providerType as providerType
,P.username as username
,P.password as password
,P.licenceInformation as licenceInformation
,PP.idProviderParameter as idProviderParameter
,PP.name as name
,PP.value as value
from [dbo].[msg_Provider] AS P
left outer join [dbo].[msg_ProviderParameter] AS PP on P.idProvider = PP.idProvider
where P.idProvider = #{idProvider}
</select>
Upvotes: 1