ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "McCORMICK, Paul" <Paul.McCORM...@doir.wa.gov.au>
Subject ResultMap ClassCastException
Date Wed, 25 May 2005 04:21:13 GMT

I am attempting to run a simple query and use a resultMap within a resultMap.  I end up with
a ClassCastException below.  Do you know what I'm doing wrong?

<sqlMap namespace="Bond">
	<resultMap id="FooResultMap" class="my.pkg.Foo" >
		<result property="fooId" column="FOO_ID" />
	</resultMap>

	<resultMap id="BarResultMap"  class="my.pkg.Bar" >
		<result property="barId" column="BAR_ID" />
		<result property="foo" resultMap="Bond.FooResultMap"/>			
	</resultMap>

      <!-- Query to select from a dummy table -->
	<select id="getBar" resultMap="Bond.BarResultMap">
		select 1 as BAR_ID, 2 as FOO_ID
		from sysibm.sysdummy1
	</select>	  	  
</sqlMap>

public class Bar {
    private Integer barId;
    private Foo foo;
    //Getter, Setter and Constructor code omitted.
}
public class Foo {
    Integer fooId;
    //Getter, Setter and Constructor code omitted.
}

public static void main(..) {
      // Run the query and get the exception below.
	List list = sqlMap.queryForList("getBar", null);
}

--- The error happened while setting a property on the result object. 
--- Cause: com.ibatis.sqlmap.client.SqlMapException: Error instantiating collection property
for mapping 'foo'.  Cause: java.lang.ClassCastException: my.pkg.Foo
Caused by: java.lang.ClassCastException: my.pkg.Foo
Caused by: com.ibatis.sqlmap.client.SqlMapException: Error instantiating collection property
for mapping 'foo'.  Cause: java.lang.ClassCastException: my.pkg.Foo
Caused by: java.lang.ClassCastException: my.pkg.Foo
	at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:184)
	at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:119)
	at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
	at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
	at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:105)
	at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:77)
	at au.gov.wa.doir.test.IBatsTest.main(IBatsTest.java:48)

I am running the code in IBM websphere 5.1.0
I am using iBatis 2.1.0.565

Paul McCormick
IT Consultant
DEPARTMENT OF INDUSTRY AND RESOURCES
100 Plain Street, East Perth, Western Australia 6004
Telephone: +61 8 922 23481, 0422 958 958
www.doir.wa.gov.au



"DISCLAIMER: This email, including any attachments, is intended only for use by the addressee(s)
and may contain confidential and/or personal information and may also be the subject of legal
privilege. If you are not the intended recipient, you must not disclose or use the information
contained in it. In this case, please let me know by return email, delete the message permanently
from your system and destroy any copies.

Before you take any action based upon advice and/or information contained in this email you
should carefully consider the advice and information and consider obtaining relevant independent
advice.
Mime
View raw message