You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Da...@ltx.com on 2008/08/15 17:05:36 UTC
Input in ResultMap
Hi,
This is probably an FAQ, but I couldn't find any examples of it. It seems
to be related to the N+1 problem, but I think there is a fundamental
difference in that no database lookup should be necessary.
Is there a way to specify that the value in a result map should be equal
to an input parameter? Here is an example (I know this itself will not
work):
<resultMap id="MyResultMap" class="MyResultClass">
<result property="myEntity" value="#myInputEntity#" />
<result property="colA" column="colA" />
<result property="colB" column="colB" />
</resultMap>
<statement id="MyStatement" resultMap="MyResultMap">
SELECT colA, colB FROM myTable WHERE
val1=#myInputEntity.prop1# AND
val2=#myInputEntity.prop2#
</statement>
Obviously, the input is actually a map or another entity with a property
named "myInputEntity". Here are some drivers for why I am looking for
something like this:
1) myInputEntity could have many properties, so returning each one from
the query and mapping them manually would be annoying at best.
2) Looking up myInputEntity with another query using an ID is both
inefficient and unnecessary work. The entity could also have been
generated by some other system, meaning there may be no way to map it to
another Ibatis statement.
3) I am hoping to avoid writing custom post-query handlers, as this is a
very common case for me, and that could get messy.
Thanks,
David