I have tried an example from every google result I could find and none
worked:

http://www.nabble.com/problem-with-selectKey-and-parameter-map-tf1762050.html#a4794206
http://opensource.atlassian.com/confluence/oss/display/IBATIS/Environment+Specific+Information
http://raibledesigns.com/wiki/CreateDAOiBATIS.html
http://www.mail-archive.com/[email protected]/msg01033.html
http://opensource.atlassian.com/confluence/oss/pages/viewpage.action?pageId=407


The only statement that works is removing the selectKey as such:
    <parameterMap id="hbaContactParameters" class="com.foo.to.ContactTO">  
        <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">
        
        <![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 (hba_contact_seq.NEXTVAL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?)
        ]]>
    </insert>  

If I do the following, I get a unique key constraint violation because "id"
in ContactTO
is set to 0, and the selectKey does not override this value.  So this
configuration fails.

    <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 keyProperty="hbc_contact_id" resultClass="long">
            <![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>
    
If I do the following configuration and change the keyProperty to "id" to
match the 
parameter name in the parameterMap, I still get a unique key constraint
violation because
selectKey is still not mapping the keyProperty="id" to the parameter
property id.
    
    <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 keyProperty="id" resultClass="long">
            <![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>  
    
If I add the type="pre", hoping it does something but the documentation does
not
explain this at all.  My sqlMap configuration validates fine against the
iBatis dtd
when I use an XML ide, but when I deploy and run a test, I get a massive SAX
exception.
Which says that the iBatis dtd that is being used is not the same dtd posted
on the url
http://www.ibatis.com/dtd/sql-map-2.dtd, which has a property of type.  The
SAX
exception is saying the dtd does not have an attribute of type for
selectKey,
so it must be defined in the dtd.
    
    <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 keyProperty="id" resultClass="long" type="pre">
            <![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>      
    
SAXException:

Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: com.ibatis.common.exce
ption.NestedRuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. 
Cause: com.ibatis.common.
xml.NodeletException: Error parsing XML.  Cause:
org.xml.sax.SAXParseException: Attribute "type" mus
t be declared for element type "selectKey".
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: org.xml.sax.SAXParseEx
ception: Attribute "type" must be declared for element type "selectKey".
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing
XPath '/sqlMapConfig/sq
lMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: org.xml.sax.SAXPar
seException: Attribute "type" must be declared for element type "selectKey".
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: org.xml.sax.SAXParseEx
ception: Attribute "type" must be declared for element type "selectKey".
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
        at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:78)

        ... 30 more
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing
XPath '/sqlMapConfig/sq
lMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: org.xml.sax.SAXPar
seException: Attribute "type" must be declared for element type "selectKey".
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: org.xml.sax.SAXParseEx
ception: Attribute "type" must be declared for element type "selectKey".
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
        at
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:114)
        at
com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:75)
        at
com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:93)
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:63)
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
        ... 31 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: org.xml.sax.SAXParseEx
ception: Attribute "type" must be declared for element type "selectKey".
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
        at
com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse(SqlMapParser.java:45)
        at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$11.process(SqlMapConfigParser.jav
a:347)
        at
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:112)
        ... 35 more
Caused by: org.xml.sax.SAXParseException: Attribute "type" must be declared
for element type "select
Key".
        at
weblogic.apache.xerces.parsers.DOMParser.parse(DOMParser.java:271)
        at
weblogic.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:201)
        at
weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuilder.java:149)
        at
com.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:150)
        at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:50)
        ... 38 more
-- 
View this message in context: 
http://www.nabble.com/selectKey-and-parameterMap-issue-tf2118776.html#a5854157
Sent from the iBATIS - User - Java forum at Nabble.com.

Reply via email to