Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 38164 invoked from network); 26 Mar 2007 07:02:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Mar 2007 07:02:52 -0000 Received: (qmail 6037 invoked by uid 500); 26 Mar 2007 07:02:57 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 6018 invoked by uid 500); 26 Mar 2007 07:02:56 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 6007 invoked by uid 99); 26 Mar 2007 07:02:56 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Mar 2007 00:02:56 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [83.247.21.92] (HELO mail.local.wis.nl) (83.247.21.92) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 26 Mar 2007 00:02:46 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C76F74.ADE1E2E0" Subject: RE: Polymorphism question Date: Mon, 26 Mar 2007 09:02:22 +0200 Message-ID: <50CA25BD6EEA954FA592C097399942E31915A201@CM1.wis.local> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Polymorphism question Thread-Index: AcdtfASbvfxbum7FRTSnPzB9yvX1kgAEzi1gAHlK8HA= From: "Niels Beekman" To: X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. ------_=_NextPart_001_01C76F74.ADE1E2E0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, =20 I've been experiencing this 'problem' too. I currently use the left joins solution when there are <=3D3 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. =20 Niels =20 ________________________________ From: Poitras Christian [mailto:Christian.Poitras@ircm.qc.ca]=20 Sent: vrijdag 23 maart 2007 22:22 To: user-java@ibatis.apache.org Subject: RE: Polymorphism question =20 Hi. =20 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 =3D ChildTable1.id LEFT JOIN ChildTable2 ON BaseTable.id =3D 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. =20 Still, you can do a twist with discriminator tag. 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. =20 Christian =20 =20 ________________________________ From: Mikael Andersson [mailto:mail.micke@gmail.com]=20 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 |=20 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.=20 I have found information which shows how the 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.=20 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).=20 Any help appreciated, Mike ------_=_NextPart_001_01C76F74.ADE1E2E0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

I’ve been experiencing this = ‘problem’ too. I currently use the left joins solution when there are <=3D3 = 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 =3D ChildTable1.id LEFT JOIN ChildTable2 ON BaseTable.id = =3D 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=3D"baseMap">

  <discriminator column=3D"type">

    <subMap value=3D"1" = resultMap=3D"child1">

    <subMap value=3D"2" = resultMap=3D"child2">

  = </discriminator>

</resultMap>

<resultMap = id=3D"map1">

  <result property=3D"subClass" property=3D"id" select=3D"getChildInfo1"/>

</resultMap>

<resultMap = id=3D"map2">

  <result property=3D"subClass" property=3D"id" select=3D"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=3D"map1">

  <result property=3D"this" property=3D"id" select=3D"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

------_=_NextPart_001_01C76F74.ADE1E2E0--