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 Tom Duffey <td...@utilivisor.com> on 2006/10/11 23:50:31 UTC
Type handlers for associated objects
Hi All,
Before I try this I'd like some feedback to see if I'm wasting my
time or if there is a better alternative. Suppose I have a building
and a building has electric, water and gas meters. My SQL maps for
this scenario look something like:
<sqlMap namespace="Building">
<resultMap id="result" class="foo.bar.Building">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="meters" column="id"
select="Meter.listByBuilding"/>
</resultMap>
...
</sqlMap>
<sqlMap namespace="Meter">
<resultMap id="result" class="foo.bar.BaseMeter">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="type" column="type_name"/>
</resultMap>
...
</sqlMap>
My class model, however, has concrete classes defined for each type
of meter, i.e., Building, BaseMeter, ElectricMeter, WaterMeter,
GasMeter. With a Building I want to get a list of Electric Meters
but given the above result map all of my building's meters will be
the more generic BaseMeter type.
Can I use a type handler to convert results of type BaseMeter to
their more appropriate concrete classes by checking the "type"
property of the base meter result? Is there some other way that
people handle this? My situation is more complicated than what I
describe above so I want to avoid having to create database tables,
iBATIS mappings, etc. for each concrete meter type.
Best Regards,
Tom
Re: Type handlers for associated objects
Posted by Tom Duffey <td...@utilivisor.com>.
On Oct 11, 2006, at 4:50 PM, Tom Duffey wrote:
> Can I use a type handler to convert results of type BaseMeter to
> their more appropriate concrete classes by checking the "type"
> property of the base meter result? Is there some other way that
> people handle this? My situation is more complicated than what I
> describe above so I want to avoid having to create database tables,
> iBATIS mappings, etc. for each concrete meter type.
Never mind, I think this post I just found answers my question:
http://www.mail-archive.com/user-java@ibatis.apache.org/msg05332.html
Tom