ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Duffey <tduf...@utilivisor.com>
Subject Type handlers for associated objects
Date Wed, 11 Oct 2006 21:50:31 GMT
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

Mime
View raw message