ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niels Beekman" <n.beek...@wis.nl>
Subject RE: abstract property
Date Thu, 13 Sep 2007 06:51:03 GMT
How could iBATIS throw an InstantiationException when you're not even
telling it the name of your abstract class? Please post the full
exception stacktrace and your result maps.


-----Original Message-----
From: Kenny Pearce [mailto:kenny.pearce@hxti.com] 
Sent: woensdag 12 september 2007 20:46
To: user-java@ibatis.apache.org
Subject: abstract property

	I am trying to use iBatis in a case where I have an object
like the following:

class Foo{
    String fooString;
    Bar myBar;
    //getters and setters omitted

abstract class Bar{
    String barString;
    //getters and setters omitted

class SubBar extends Bar{
    String subBarString;
    //getters and setters omitted

I would like to be able to do this:

<resultMap id="fooResultMap" class="Foo">
    <result property="fooString" column="foo"/>
    <result property="myBar" resultMap="barResultMap"/>

<resultMap id="barResultMap" class="SubBar">
    <result property="barString" column="bar"/>
    <result proprty="subBarString" column="sub_bar"/>

<select id="fooSelect" parameterClass="string" resultClass="Foo" 
    SELECT foo, bar, sub_bar FROM table WHERE foo = #value#

But that gives an InstantiationException (despite the fact that the 
barResultMap has the class SubBar, which is concrete, specified). Next I

tried using a discriminator and making a separate barResultMap and 
subBarResultMap (where subBarResultMap extends barResultMap) with 
<subMap value="*" ...> on a column that is never null (I'm not sure if 
wildcard is supported - I couldn't find discriminator in the docs, but 
it's not listed on the undocumented features page). That still threw an 
exception. Next, I changed the select statement to (the equivalent of):

    SELECT foo, bar, sub_bar, 1 as use_submap FROM table WHERE foo =

and used:

<discriminator column="use_submap" javaType="int">
	<subMap value="1" resultMap="subBarResultMap"/>

But no go there either.

Is there any way to do this, short of creating a custom object factory?


Kenny Pearce
Hx Technologies

View raw message