I don't see where you're inserting id in your insert statement.  You'll need to add it as a parameter even if you use selectKey.

Diran


jaybytez wrote:
When I use a selectKey in conjunction with a parameterMap...the selectKey
does not appear to work in mapping its value into the insert statement.  I
originally did not have an id field in my object, so I added one and
included it in the parameterMap thinking this would help.  I then made the
selectKey output map to the id parameter thinking it would populate id with
the result from selectKey...it doesn't.  I tested the selectKey separate and
it works.  But in this example below...I keep getting integrity constraint
violations because the selectKey and insert are trying to insert 0...or
something.  Any help on this?

Thanks,

jay

    <parameterMap id="hbaContactParameters" class="com.foo.to.ContactTO">  
        <parameter property="id" jdbcType="NUMERIC"/>
        <parameter property="tscName" jdbcType="VARCHAR"/>
        <parameter property="contactName" jdbcType="VARCHAR"/>
        <parameter property="contactDate" jdbcType="DATE"
javaType="dateTime"/>
        <parameter property="issueResolvedIndicator" jdbcType="NUMERIC"/>
        <parameter property="followUpRequiredIndicator" jdbcType="NUMERIC"/>
        <parameter property="followUpRequiredDescription"
jdbcType="VARCHAR"/>
        <parameter property="contactTypeDescription" jdbcType="VARCHAR"/>
        <parameter property="contactReasonTypeDescription"
jdbcType="VARCHAR"/>
        <parameter property="contactType" jdbcType="NUMERIC"
javaType="com.foo.to.ContactType"/>
        <parameter property="contactMethodType" jdbcType="NUMERIC"
javaType="com.foo.to.ContactMethodType"/>
        <parameter property="contactReasonType" jdbcType="NUMERIC"
javaType="com.foo.to.ContactReasonType"/>
    </parameterMap>
   
    <insert id="insertHBAContact"
        parameterMap="hbaContactParameters">
        <selectKey resultClass="long" keyProperty="id">
            <![CDATA[
                SELECT hba_contact_seq.NEXTVAL FROM DUAL
            ]]>
        </selectKey>
       
        <![CDATA[    
            INSERT INTO hba_contact_hbc
                ( hbc_contact_id, hbc_tsc_name, hbc_contact_name,
hbc_contact_date,
                  hbc_issue_resolved_ind, hbc_follow_up_required_ind,
                  hbc_follow_up_required_desc, hbc_contact_type_desc,
                  hbc_reason_desc, hbc_fk_contact_type_id,
hbc_fk_contact_method_id,
                  hbc_fk_contact_reason_id )
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        ]]>
    </insert>


  

Reply via email to