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 Dave Rodenbaugh <dr...@WILDBLUECORP.COM> on 2006/12/12 00:28:37 UTC

Using parameterMaps

Hello all,

I have a question regarding the valid values for the attribute "class"
in the parameterMap.  So far, the docs make it clear that I can use
pkg-qualified names there, but don't say much else.

If I have:

	<parameterMap id="orderByStatusAndType" class="map">
		<parameter property="orderStatus"
javaType="java.lang.String"/>
		<parameter property="orderType"
javaType="java.lang.String"/>
	</parameterMap>

That is used thusly:

	<select id="findOrderMasterByStatusAndOrderType"
			  parameterMap="orderByStatusAndType"
			  resultClass="OrderMaster">
	    <include refid="OrderMasterBase"/>
	    <![CDATA[
	    WHERE Order_Status = #orderStatus# AND Order_Type =
#orderType#
	    ]]>
	</select>

Is 'map' a valid value in the class attribute?  If it isn't, what if I
want to pass data that aren't represented as a class/POJO/bean, such as
a list of parameters--(I tried passing java.util.HashMap instead without
much success)?

Thanks,
-Dave



Re: Using parameterMaps

Posted by Larry Meadors <lm...@apache.org>.
As Jeff said, remember is that anywhere that you specify a result or
parameter class, you can use a type alias (which is what "map" and
"hashmap" are - type aliases for "java.util.Map" and
"java.util.HashMap"). The user guide lists most of the type aliases,
and you can also define your own.

Also, in most cases, parameter maps and result maps are not required,
so you may be able to use just this:

<select id="findOrderMasterByStatusAndOrderType" resultClass="OrderMaster">
  <include refid="OrderMasterBase"/>
  WHERE Order_Status = #orderStatus# AND Order_Type = #orderType#
</select>

Keep it simple. :-)

Larry


On 12/11/06, Jeff Butler <je...@gmail.com> wrote:
> Several things...
>
> 1. map is OK - it is a predefined type alias
> 2. java.util.HashMap is OK also
> 3. When using parameter maps, you must specify question marks in the SQL
> instead of property names.  This is likely the cause of your problem.  For
> this reason, I recommend that you forego the use of explicit parameter maps
> altogether, the inline syntax is much clearer IMHO
> 4.  You don't need CDATA here (it's not causing the problem, but I think
> it's bad practice to write a CDATA section unless you really need it - in
> other words, very rarely)
>
> So, I would delete the <parameterMap> and do this instead:
>
> <select id="findOrderMasterByStatusAndOrderType"
>             parameterClass="map"
>             resultClass="OrderMaster">
>   <include refid="OrderMasterBase"/>
>   WHERE Order_Status = #orderStatus# AND Order_Type = #orderType#
> </select>
>
> Jeff Butler
>
>
>
> On 12/11/06, Dave Rodenbaugh <dr...@wildbluecorp.com> wrote:
> > Hello all,
> >
> > I have a question regarding the valid values for the attribute "class"
> > in the parameterMap.  So far, the docs make it clear that I can use
> > pkg-qualified names there, but don't say much else.
> >
> > If I have:
> >
> >        <parameterMap id="orderByStatusAndType" class="map">
> >                <parameter property="orderStatus"
> > javaType="java.lang.String"/>
> >                <parameter property="orderType"
> > javaType="java.lang.String"/>
> >        </parameterMap>
> >
> > That is used thusly:
> >
> >        <select id="findOrderMasterByStatusAndOrderType"
> >
> parameterMap="orderByStatusAndType"
> >                          resultClass="OrderMaster">
> >            <include refid="OrderMasterBase"/>
> >            <![CDATA[
> >            WHERE Order_Status = #orderStatus# AND Order_Type =
> > #orderType#
> >            ]]>
> >        </select>
> >
> > Is 'map' a valid value in the class attribute?  If it isn't, what if I
> > want to pass data that aren't represented as a class/POJO/bean, such as
> > a list of parameters--(I tried passing java.util.HashMap instead without
> > much success)?
> >
> > Thanks,
> > -Dave
> >
> >
> >
>
>

Re: Using parameterMaps

Posted by Jeff Butler <je...@gmail.com>.
Several things...

1. map is OK - it is a predefined type alias
2. java.util.HashMap is OK also
3. When using parameter maps, you must specify question marks in the SQL
instead of property names.  This is likely the cause of your problem.  For
this reason, I recommend that you forego the use of explicit parameter maps
altogether, the inline syntax is much clearer IMHO
4.  You don't need CDATA here (it's not causing the problem, but I think
it's bad practice to write a CDATA section unless you really need it - in
other words, very rarely)

So, I would delete the <parameterMap> and do this instead:

<select id="findOrderMasterByStatusAndOrderType"
            *parameterClass*="map"
            resultClass="OrderMaster">
  <include refid="OrderMasterBase"/>
  WHERE Order_Status = #orderStatus# AND Order_Type = #orderType#
</select>

Jeff Butler


On 12/11/06, Dave Rodenbaugh <dr...@wildbluecorp.com> wrote:
>
> Hello all,
>
> I have a question regarding the valid values for the attribute "class"
> in the parameterMap.  So far, the docs make it clear that I can use
> pkg-qualified names there, but don't say much else.
>
> If I have:
>
>        <parameterMap id="orderByStatusAndType" class="map">
>                <parameter property="orderStatus"
> javaType="java.lang.String"/>
>                <parameter property="orderType"
> javaType="java.lang.String"/>
>        </parameterMap>
>
> That is used thusly:
>
>        <select id="findOrderMasterByStatusAndOrderType"
>                          parameterMap="orderByStatusAndType"
>                          resultClass="OrderMaster">
>            <include refid="OrderMasterBase"/>
>            <![CDATA[
>            WHERE Order_Status = #orderStatus# AND Order_Type =
> #orderType#
>            ]]>
>        </select>
>
> Is 'map' a valid value in the class attribute?  If it isn't, what if I
> want to pass data that aren't represented as a class/POJO/bean, such as
> a list of parameters--(I tried passing java.util.HashMap instead without
> much success)?
>
> Thanks,
> -Dave
>
>
>