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/user-java@ibatis.apache.org/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