Hello, regarding my last question, let me simplify this question:
I have a resultMap that contains another select statement that populates
one of the column,
If the resultMap contains 10 column, which 2 of them contains another
select statement, then this is what happens:
        - if i map the results to a Map or a class, then the result is
correct (10 columns)
        - if i use resultMap="xml", then the result is only 8 columns
(without the 2 which contains another select)

have anyone experienced this before? or a bug?

Thanks,
Yusuf.

-----Original Message-----
From: Yusuf 
Sent: Tuesday, February 07, 2006 2:02 PM
To: user-java@ibatis.apache.org
Subject: Different Number of Columns in resultClass with xml and with
HashMap


Hi,
I have a working query and the resultmap is like this:

<resultMap id="resultParent" class="java.util.HashMap">
        <result property="NAMA_PP" column="NAMA_PP" javaType="string"
jdbcType="VARCHAR2" nullValue=""/>
        <result property="BEGDATE" column="BEGDATE" javaType="string"
jdbcType="VARCHAR2" nullValue=""/>
        <result property="ENDDATE" column="ENDDATE" javaType="string"
jdbcType="VARCHAR2" nullValue=""/>
        <result property="SAR_POLIS" column="{spaj=REG_SPAJ,
tahunKe=TAHUN_KE}" javaType="double" jdbcType="NUMBER" nullValue="0"
select="selectChild1"/>
        <result property="MSPR_PREMIUM" column="MSPR_PREMIUM"
javaType="double" jdbcType="NUMBER" nullValue="0"/>

        <result property="PREMI_RIDER" column="REG_SPAJ"
javaType="double" jdbcType="NUMBER" nullValue="0"
select="selectChild2"/>
        <result property="PREMI_EXTRA" column="REG_SPAJ"
javaType="double" jdbcType="NUMBER" nullValue="0"
select="selectChild3"/>
</resultMap>

So far there is no problem (all the inner fields also populated with the
selectChild1, selectChild2, ..),
but when i tried changing the resultMap class to xml like this:

<resultMap id="resultParent" class="xml">
        <result property="NAMA_PP" column="NAMA_PP" javaType="string"
jdbcType="VARCHAR2" nullValue=""/>
        <result property="BEGDATE" column="BEGDATE" javaType="string"
jdbcType="VARCHAR2" nullValue=""/>
        <result property="ENDDATE" column="ENDDATE" javaType="string"
jdbcType="VARCHAR2" nullValue=""/>
        <result property="SAR_POLIS" column="{spaj=REG_SPAJ,
tahunKe=TAHUN_KE}" javaType="double" jdbcType="NUMBER" nullValue="0"
select="selectChild1"/>
        <result property="MSPR_PREMIUM" column="MSPR_PREMIUM"
javaType="double" jdbcType="NUMBER" nullValue="0"/>

        <result property="PREMI_RIDER" column="REG_SPAJ"
javaType="double" jdbcType="NUMBER" nullValue="0"
select="selectChild2"/>
        <result property="PREMI_EXTRA" column="REG_SPAJ"
javaType="double" jdbcType="NUMBER" nullValue="0"
select="selectChild3"/>
</resultMap>

and used a custom type handler to process the xml like this (i'm using
dom4j):

static class XmlRowHandler implements RowHandler {
        private Document domDocument;
        public XmlRowHandler(String xmlResultName) {
                domDocument = DocumentHelper.createDocument();
                getDomDocument().addElement(xmlResultName);
        }
        public void handleRow(Object object) {
                try {
                        Document xmlFragment = DocumentHelper
                                        .parseText((String) object);
                        Element xmlElement =
xmlFragment.getRootElement();
        
getDomDocument().getRootElement().add(xmlElement);
                } catch (DocumentException e) {
                }
        }
        public Document getDomDocument() {
                return domDocument;
        }
}

private Document queryXml(String queryId, Object param) {
        RowHandler rowHandler = new XmlRowHandler("result");
        getSqlMapClientTemplate().queryWithRowHandler(queryId, param,
rowHandler);
        Document doc = ((XmlRowHandler) rowHandler).getDomDocument();
        return doc;             
}

the result is different. Only the columns without inner selects are
shown, so instead of having 7 columns per row, there is only 4 columns
per row. I have used this custom xml handler for other queries and it
ran well.

Is this a bug in ibatis, or I've done something wrong?

Thank you for your help and regards,
Yusuf S.


Reply via email to