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 Yusuf <Yu...@ekalife.co.id> on 2006/02/07 08:02:27 UTC

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.