Could you use a nested select? Check out page 34, under "Complex Properties": http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf
The idea is that one ResultMap contains a complex type that consists of the results from another select. So if tableA has a primary key, and tableB has a foreign key to the primary key in tableA, you'd have a ResultMap of tableA results, and in each result from tableA exists a List (or Object) of ResultMap(s) that match the foreign key in tableB. One iBATIS query would execute the primary select to gather tableA results, and then automatically, a separate select will execute to gather the results for each tableA result and insert them into tableA's ResultMap. I might be incorrect, but I think the docs might be wrong. It says: <result property="category" column="PRD_CAT_ID" select="getCategory"/> and it should be: <result property="category" column="PRD_ID" select="getCategory"/> because you want to map PRD_ID from PRODUCT into the getCategory select. -Ryan On Thu, Mar 13, 2008 at 2:54 AM, Eric Andres <[EMAIL PROTECTED]> wrote: > Hello, > > I have a problem writing a polymorphic query. As I am new to iBatis, I > started digging the list archive and stumbled upon the discriminator > and submap tags, and I also found this in the archives: > http://www.mail-archive.com/[email protected]/msg00070.html > , my situation is pretty close to Niels', but there was no solution in > that thread... > The situation I'm in is this: I have a type hierarchy representing > events consisting of a base class (call it Event) and a subclass for > each event type (30+ currently). It's representation in the database > was done with a table-per-subclass strategy. > > I want to write a query that fetches an event based on it's ID. The > problem is that I don't know the event type I'm going to fetch in > advance, and I want to avoid a 30-table join. Is there a way a > delaying the join to a second query after the 'discrimination'? > Something like > > <resultMap id="Event" class="BaseEvent"> > ... > <result property="ts" column="timestamp/> > <discriminator javaType="string" column="type"> > <subMap value="userLoggedIn" > select="addUserLoggedInProps"/> > ... > </discriminator> > </resultMap> > > ... > > <select id="addUserLoggedInProps" parameterClass="int" > resultMap="userLoggedInEvent"> > select * from event, userloggedinevent > where event.id=userloggedin.eventid and event.id=#value# > </select> > > ... > <resultMap id="userLoggedInEvent" extends="Event"> > ... > <result property="userId" column="userid"/> <!-- specific to > userLoggedInEvent --> > ... > </resultMap> > > > Sorry for the lengthy post. Any help greatly appreciated... > > Thanks for your time, > > Eric > >
