ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btymvios <by...@scube.co.za>
Subject Collection with composite key in XML mapping
Date Thu, 05 Nov 2009 09:35:27 GMT

Hi All,

Please could someone assist, I know this might be a silly question with a
simple answer but I have tried all examples I have found, I have read the
documentation and I have searched the forums and the internet but to no
avail.

I am using the latest beta version of iBatis 3 (beta 5) but had the same
problem with beta 4. In iBatis v2x these complex key mappings worked fine.

The documentation states:

"Note: To deal with composite keys, you can specify multiple column names
to pass to the nested select statement by using the syntax
column=”{prop1=col1,prop2=col2}”. This
will cause prop1 and prop2 to be set against the parameter object for the
target nested select statement."

However when I specify this with multiple columns for a collection the
nested select is never run and no error is reported. In the referenced
"select" I am accessing the parameters by #{param1Name} and #{param2Name}
(where param1Name is the name of the first param etc..).

If I remove this and only specify one parameter like column="col_1" then the
referenced "select" is executed and the same param is used for both
parameter mapping in the select. So the collection mapping can access the
nested select and return a list of the correct type (albeit with a lot of
incorrect rows due to not matching on the full complex key) but not when I
have complex keys specified.

What is the correct notation for using multiple columns for complex keys
from a "collection" mapping. There are no examples in the documentation
other than the excerpt above. I have also not found any workable examples on
the internet.

I have found references on the internet to accesing params with @{param}
instead of #{param} which I have also tried with no luck. I have also tried
specifying paramaterType="map" on the nested select with no results.

ResultMap (XML file 1):
<resultMap id="myResultMap" type="ResultClass">
    <id property="id" column="id" />
    <id property="clientId" column="client_id" />
    <result property="someProp" column="some_prop" />
    <collection property="myList" column="{id=id,clientId=client_id}"
javaType="ArrayList" ofType="MyType"
select="other.xml.namespace.MyTypeNS.nestedSelect" />
</resultMap>

Select (XML file 2):
<mapper namespace="other.xml.namespace.MyTypeNS">
    <resultMap id="myTypeResultMap" type="MyType">
         <!-- mapping of MyType -->
    </resultMap>
    <select id="nestedSelect" parameterType="map"
resultMap="myTypeResultMap">
        SELECT *
        FROM my_type_table
        WHERE other_id = #{id} AND client_id = #{client_id}
    </select>
</mapper>

Thanks for your time.
Byron
-- 
View this message in context: http://old.nabble.com/Collection-with-composite-key-in-XML-mapping-tp26208650p26208650.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Mime
View raw message