ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niels Beekman" <n.beek...@wis.nl>
Subject RE: How do I apply individual properties from a resultMap to another resultMap
Date Wed, 14 Mar 2007 17:44:50 GMT
Don't know of a pretty solution, but you can do the following:

1. use queryForObject() to create an object with either values (stored proc or regular query)
2. use the constructed object and pass it to queryForObject() as 'resultObject' parameter
(stored proc or regular query, depending on first choice)

So it's up to you to define 'logically', not the prettiest solution, but it should work I
think.

HTH,

Niels
________________________________________
From: Andy Thompson [mailto:arthomps@gmail.com] 
Sent: woensdag 14 maart 2007 17:35
To: user-java@ibatis.apache.org
Subject: How do I apply individual properties from a resultMap to another resultMap

I've run into a situation where i want to use two separate queries to build one domain object. 
The reason being that I need to use a stored procedure for several attributes and standard
SQL for the rest.  Unfortunately I can't fix the stored proc to do everything I need, nor
can I bypass that proc for business reasons. 

For example the below works, but doesn't do exactly what I want:

<resultMap id="FinalObject" class="com.domain.FinalObject">
    <result property="propertyA" column="A" /> 
    <result property="propertyB" column="B" />
    <result property="propertyC" select="execSQL"/>
</resultMap>

<procedure id="execStoredProc" resultMap="FinalObject"    > 
    {call someProc(#value#) }
</procedure>

<resultMap id="sqlRS" class="java.util.Date">
   <result property="propertyC" column="columnC"/>
</resultMap>

<select id="execSQL" resultMap="sqlRS">
   select C from table where something=#value#
</select>

What I would really like is to modify the above such that sqlRS returns a map.  and I can
insert propertyC directly into FinalObject.  The below has broken syntax - but illustrates
logically what I would like. 

Essentially:
<resultMap id="FinalObject" class="com.domain.FinalObject">
    <result property="propertyA" column="A" />
    <result property="propertyB" column="B" />
    <result property="propertyC" select="execSQL.propertyC"/> <!-- insert one
property from sqlRS into FinalObject-->
    <result property="propertyD" select="execSQL.propertyD "/> <!-- insert another
property from sqlRS into FinalObject-->
</resultMap>

<procedure id="execStoredProc" resultMap="FinalObject"    >
    {call someProc(#value#) }
</procedure>

<resultMap id="sqlRS">
   <result property="propertyC" column="columnC"/>
<result property="propertyD" column="columnD"/>
</resultMap>

<select id="execSQL" resultMap="sqlRS">
   select C, D from table where something=#value#
</select>

Is there a working syntax to accomplish logically what I'm trying to do above?

-- 
Andrew R. Thompson
Currently in D.C. Consulting 

Mime
View raw message