ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Andres <eric.and...@gmail.com>
Subject Discriminator and Table per subclass
Date Thu, 13 Mar 2008 09:54:56 GMT

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"/>


<select id="addUserLoggedInProps" parameterClass="int"  
	select * from event, userloggedinevent
	where event.id=userloggedin.eventid and event.id=#value#

<resultMap id="userLoggedInEvent" extends="Event">
	<result property="userId" column="userid"/> <!-- specific to  
userLoggedInEvent -->

Sorry for the lengthy post.  Any help greatly appreciated...

Thanks for your time,


View raw message