Allow parameters as values in composite keys
--------------------------------------------
Key: IBATIS-412
URL: https://issues.apache.org/jira/browse/IBATIS-412
Project: iBatis for Java
Issue Type: New Feature
Components: SQL Maps
Affects Versions: 2.3.0
Reporter: M.H. Avegaart
Assume a master table TABLE1 with fields KEY1 and FIELD1 (primary key KEY1) and
a detail table TABLE2 with fields KEY, KEY2 and FIELD2 (composite primary key
KEY1, KEY2). TABLE1 is mapped on a class Table1, TABLE2 is mapped on a class
Table2 and Table1 has a list property that contains a List of Table2 objects.
I would like to query for all Table1 objects with a specific field1 value
together with the corresponding Table2 objects with a specific key2 value, but
this is currently not possible without joining TABLE1 and TABLE2 in a single
query (which I can't use because I really need to use lazy loading !).
Would it be possible to change SQL Maps to allow the following syntax:
<parameterMap id="params1" class="test.MyParams1">
<parameter property="field1" />
<parameter property="key2" />
</parameterMap>
<resultMap id="result1" class="test.Table1">
<result property="key1" column="KEY1" />
<result property="field1" column="FIELD1" />
<result property="list" column="{key1=KEY1,key2=#key2#}"
select="select2" />
</resultMap>
<select id="select1" parameterMap="params1" resultMap="result1">
<![CDATA[select
KEY1,
FIELD1
from TABLE1
where
FIELD1 = ?]]>
</select>
<parameterMap id="params2" class="test.MyParams2">
<parameter property="key1" />
<parameter property="key2" />
</parameterMap>
<resultMap id="result2" class="test.Table2">
<result property="key1" column="KEY1" />
<result property="key2" column="KEY2" />
<result property="field2" column="FIELD2" />
</resultMap>
<select id="select2" parameterMap="params2" resultClass="test.MyResult2">
<![CDATA[select
KEY1,
KEY2,
FIELD2
from TABLE2
where
KEY1 = ? and
KEY2 = ?]]>
</select>
Here, the column attribute for the list field specifies the KEY1 column and the
key2 parameter as parameters for the select2 query.
ps. I tried to add the field2 parameter as a field to the select statement of
the select1 query, but most databases (DB2 in my case) don't allow this.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.