Thursday, September 13, 2007

iBatis- Passing more than one column in nested selects

Take a look at my recent post "Chaining selects in iBatis" which explains how to chain selects for related objects. There is also a way of passing more than one column, all you have to do change this line

< property="Address" column="Id" javatype="Address" select="Address.getAddressById">
to
< property="Address" column="{id=Id, name=Name}" javatype="Address" select="Address.getAddressById">

and in your result map.

< select id="getAddressById" parameterclass="java.lang.Long" resultmap="Address">
SELECT Street, City, State, ZIP FROM Address WHERE id = #id# And name=#name#
lt /select>

1 comment:

Anonymous said...

Are you sure this is correct? getAddressById has parameterclass="java.lang.Long", and there are no properties in a Long for id and name? :)