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 jaybytez <ja...@gmail.com> on 2006/06/20 19:31:25 UTC

selectKey not working - #value# is repeating id.

I have the following insert into a codes lookup table:

  <insert id="insertBatchFacilityServiceLookup"
    parameterClass="string">
    <selectKey resultClass="int" >
        <![CDATA[
    	SELECT foo_lookup_seq.nextval AS id 
    	FROM dual
    	]]>
	</selectKey>
    <![CDATA[
 		INSERT INTO foo_lookup ( foo_code, foo_desc ) 
 		VALUES (#id#, #value#) 
    ]]>
  </insert>

I am sending a String into this insert and the String represents the
foo_desc.  But when I run this query and debug into the iBatis code...the
parameters for this query show ("This is the description", "This is the
description") instead of the (code, desc) like (10000, "This is the
description").  I assume the usage of #id# outputs the response from the
selectKey, but I think that the #value# is also outputting the response from
the selectKey and not the String from the parameterClass.  Anyway to get
around this?

Thanks,

jay blanton
--
View this message in context: http://www.nabble.com/selectKey-not-working----value--is-repeating-id.-t1819062.html#a4959670
Sent from the iBATIS - User - Java forum at Nabble.com.


Re: selectKey not working - #value# is repeating id.

Posted by Larry Meadors <lm...@apache.org>.
If your parameterclass is string, there is nowhere to put the generated id.

Use a bean or a map, and set the description on that object to the
description you want to insert.

Also, you'll want to set the keyProperty to "id" in your selectKey element.

Larry


On 6/20/06, jaybytez <ja...@gmail.com> wrote:
>
> I have the following insert into a codes lookup table:
>
>   <insert id="insertBatchFacilityServiceLookup"
>     parameterClass="string">
>     <selectKey resultClass="int" >
>         <![CDATA[
>         SELECT foo_lookup_seq.nextval AS id
>         FROM dual
>         ]]>
>         </selectKey>
>     <![CDATA[
>                 INSERT INTO foo_lookup ( foo_code, foo_desc )
>                 VALUES (#id#, #value#)
>     ]]>
>   </insert>
>
> I am sending a String into this insert and the String represents the
> foo_desc.  But when I run this query and debug into the iBatis code...the
> parameters for this query show ("This is the description", "This is the
> description") instead of the (code, desc) like (10000, "This is the
> description").  I assume the usage of #id# outputs the response from the
> selectKey, but I think that the #value# is also outputting the response from
> the selectKey and not the String from the parameterClass.  Anyway to get
> around this?
>
> Thanks,
>
> jay blanton
> --
> View this message in context: http://www.nabble.com/selectKey-not-working----value--is-repeating-id.-t1819062.html#a4959670
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>