I have a table with composite key. I want to query it in bulk in mybatis. Is it possible? if yes, how?
Table structure of table Foo with foo_id_1 and foo_id_2 as composite primary key.
{
foo_id_1 uniqueIdentifier,
foo_id_2 uniqueIdentifier,
foo_name nvarchar
}
I will have a list of foo POJOs and I want to query them to check if they exist or not. Below is for getting a single object
<select id="getFooList" resultMap="foo">
SELECT
f.foo_id_1,
f.foo_id_2,
f.foo_name
FROM foo f
WHERE f.foo_id_1 = #{foo_id_1} and f.foo_id_2 = #{foo_id_2}
</select>
<resultMap id="foo" type="Foo">
<id property="fooId1" column="foo_id_1"/>
<id property="fooId2" column="foo_id_2"/>
<result property="fooName" column="foo_name"/>
</resultMap>
But I want to fetch in bulk. Corresponding SQL query would be
Select *
From foo
Where (foo_id_1 = '1a' and foo_id_2 = '1b') or
(foo_id_1 = '2a' and foo_id_2 = '2b') or
(foo_id_1 = '3a' and foo_id_2 = '3b');