ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Riley <...@lse.ac.uk>
Subject Fwd: how to get attribute subclasses when performing eager fetch ?
Date Mon, 13 Mar 2006 17:33:26 GMT
Hi

I'm trying to write a query that joins several tables and instantiates
subclasses on the basis of discriminators.

In the business domain ther are Students who have several Enrolments (1 per
year).   Within each Enrolement they they take 0 or morel Modules (courses)
some of which may be subclasses of Module like Capped  Module (one with a max
permitted number of students).

When the Modules are selected separately (modules select="getModules") and
defined in their own sqlMap they get correctly subclassed.

However when the modules are joined as shown below, when their
resultMaps are included in the Student sqlMap, then the subclasses are
not picked up.  I first noticed this when ibatis tried to  instantiate
abstract super classes and threw instantiation exceptions.

I'm new to ibatis so sorry if I've overlooked something.

Does anyone know how to deal with this?

Thanks

Ron

I've got several resultMaps inside the Student.xml file.


e.g. in Student.xml map:

<sqlMap namespace="Student">
<resultMap id="studentEager" class="student" groupBy="linkcode">
  <result property="linkcode" column="LINKCODE" />
  ...
  <result property="studentEnrolements"
resultMap="Student.studentEnrolementEager" />

 <resultMap id="studentEnrolementEager" class="studentEnrolement"
groupBy="setid">
 <result property="setid" column="SETID" />
  ...
   <result property="modules" resultMap="Student.module" />
 </resultMap>

 <resultMap id="module" class="module" groupBy="setid,moduleid">
        <result property="setid" column="MODULE_SETID"/>
        <result property="moduleid" column="MODULE_MODULEID"/>
        <discriminator javaType="string" column="MODULE_SUBCLASS">
            <subMap value="CAP" resultMap="Student.CappedModule" />
            <subMap value="DIS"
resultMap="Student.DiscontinuedModule" />
            <subMap value="N/A"
resultMap="Student.NotAvailableModule" />
        </discriminator>
    </resultMap>

 <resultMap id="StudentCappedModule" class="cappedModule"
extends="Student.module">
     ...
    </resultMap>

    <resultMap id="StudentDiscontinuedModule" class="discontinuedModule"
extends="Student.module">
      ...
    </resultMap>

    <resultMap id="StudentNotAvailableModule" class="notAvailableModule"
extends="Student.module">
       ...
    </resultMap>

The select looks like this:

SELECT DISTINCT
            S.LINKCODE LINKCODE
            ,SE.SETID SETID
            ,M.MODULEID MODULE_MODULEID
            ,M.OWNER MODULE_OWNER
            ,SUBSTR(M.CLASSIF,1,3) MODULE_SUBCLASS
FROM
        STUDENTS S
        ,STU_ENROLMENTS SE
        ,STUMODULES SM
        ,MODULES M
WHERE
            S.LINKCODE = #linkcode#
            and
            SE.STUDENTID = S.STUDENTID
            and
            SE.SETID = SM.SETID (+)
            AND
            SE.STUDENTID = SM.STUDENTID(+)
            and
            SM.SETID = M.SETID  (+)
            AND
            SM.MODULEID = M.MODULEID (+)
ORDER BY SETID

-------------------------------------------------------

Mime
View raw message