ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikael Andersson" <mail.mi...@gmail.com>
Subject Re: Polymorphism question
Date Mon, 26 Mar 2007 07:15:53 GMT
Thanks all for you're input which I'm sure sorted out my problems.

Cheers,
 Mike

On 26/03/07, Niels Beekman <n.beekman@wis.nl> wrote:
>
>  Hi,
>
>
>
> I've been experiencing this 'problem' too. I currently use the left joins
> solution when there are <=3 tables, otherwise I just query the type and
> perform a single join, that seems to be faster than paying the overhead
> associated with the left joins.
>
>
>
> Niels
>
>
>  ------------------------------
>
> *From:* Poitras Christian [mailto:Christian.Poitras@ircm.qc.ca]
> *Sent:* vrijdag 23 maart 2007 22:22
> *To:* user-java@ibatis.apache.org
> *Subject:* RE: Polymorphism question
>
>
>
> Hi.
>
>
>
> You can always do some left joins with the id. Something like.
>
> Select id, col1, col2, type, colX, colY, colZ, colW
>
> From BaseTable LEFT JOIN ChildTable1 ON BaseTable.id = ChildTable1.id LEFT
> JOIN ChildTable2 ON BaseTable.id = ChildTable2.id
>
> Then any resultMap for these will work since the columns must be there if
> the map reads it, otherwise columns are unnecessary.
>
> This approch seems to be the only thing that would work with a join.
>
>
>
> Still, you can do a twist with discriminator tag.
>
> <resultMap id="baseMap">
>
>   <discriminator column="type">
>
>     <subMap value="1" resultMap="child1">
>
>     <subMap value="2" resultMap="child2">
>
>   </discriminator>
>
> </resultMap>
>
> <resultMap id="map1">
>
>   <result property="subClass" property="id" select="getChildInfo1"/>
>
> </resultMap>
>
> <resultMap id="map2">
>
>   <result property="subClass" property="id" select="getChildInfo2"/>
>
> </resultMap>
>
> By making sure the subClass calls setters of your main class, you can
> force a second select to be call to populate values from child table.
>
> I doudt you can make a reference to the populating object itself (being
> able to write "this" would be a cool improvement!) inside the disciminator
> when you would like a second call to database...
>
> Possible improvement.
>
> <resultMap id="map1">
>
>   <result property="this" property="id" select="getChildInfo1"/>
>
> </resultMap>
>
>
>
> Christian
>
>
>
>
>  ------------------------------
>
> *From:* Mikael Andersson [mailto:mail.micke@gmail.com]
> *Sent:* Friday, 23 March 2007 14:49
> *To:* user-java@ibatis.apache.org
> *Subject:* Polymorphism question
>
> Hi
> I have a polymorphism problem which I'm not sure is solvable by a pure
> iBATIS solution.
>
> I have a fixed database model which represents a hierarchy(very
> simplified):
>
> BaseTable
> | id |col1 | col2 | type |
>
> ChildTable1
> | id |colX | colY |
>
> ChildTable2
> | id |colZ | colW |
>
> Which has an obvious object hierarchy, and "type" contains a either 'A' or
> 'B' indicating which child table should be used.
>
> The id of the base and the child is the same, and the same id can not
> exists in the two child tables.
>
> I have found information which shows how the <discriminator> element can
> be used with a column indicating the object to create. Which solves half of
> my problem.
>
> The other half is something which I don't think is solvable, but figured
> I'd ask just in case it is.
> I need the select join statement to be modified depending on the value of
> the "type" column, which table to join with. I have no idea how to do this
> in iBATIS, and am currently leaning towards implementing this in Java logic
> (first get the type from the base table and then execute the correct select
> statement).
>
> Any help appreciated,
>  Mike
>

Mime
View raw message