If the sub classes have a common setter method then its possible the use the 
that setter as the required single result in the result map.  As you interface 
will not have setters you'll have to use any one of the sub classes 
(BlackSomething or WhiteSomething)  as the "class" attribute in the main result 
map.   The calling java code can do the cast to Isomething interface.

E,g.
<resultMap id="somethingResult" class="BlackSomething">
    <result property="id" column="ID"/>
    <discriminator column="type" javaType="string">
        <subMap value="black" resultMap="blackSomethingResult"/>
        <subMap value="white" resultMap="whiteSomethingResult"/>
    </discriminator>
</resultMap>


Paul



-----Original Message-----
From: Ilya Boyandin [mailto:[EMAIL PROTECTED]
Sent: Monday, 3 September 2007 4:39 PM
To: [email protected]
Subject: Using discriminator with an interface


Hello all,

is that possible to use discriminator with an interface without setters?

I have something like this in my mappings:

<resultMap id="somethingResult" class="ISomething">
    <discriminator column="type" javaType="string">
        <subMap value="black" resultMap="blackSomethingResult"/>
        <subMap value="white" resultMap="whiteSomethingResult"/>
    </discriminator>
</resultMap>

<resultMap id="blackSomethingResult" class="BlackSomething">
    ...
</resultMap>

<resultMap id="whiteSomethingResult" class="WhiteSomething">
    ...
</resultMap>

<select id="loadSomething" resultMap="somethingResult">
    ...
</select>

And I always get this RuntimeException: "resultMap Something.somethingResult 
must have at least one result mapping". But somethingResult can't have any 
mappings because ISomething is an interface without any setters.

Am I doing something wrong or is there any other way to accomplish this?

Thanks in advance
Ilya




FH JOANNEUM Gesellschaft mbH
Rechtsform/Legal form: GmbH
Firmenbuchgericht/Court of registry: Landesgericht für ZRS Graz 
Firmenbuchnummer/Company registration: FN 125888 f
DVR: 0813559
UID-Nr.: ATU 42361001

"DISCLAIMER: This email, including any attachments, is intended only for use by 
the addressee(s) and may contain confidential and/or personal information and 
may also be the subject of legal privilege. If you are not the intended 
recipient, you must not disclose or use the information contained in it. In 
this case, please let me know by return email, delete the message permanently 
from your system and destroy any copies.

Before you take any action based upon advice and/or information contained in 
this email you should carefully consider the advice and information and 
consider obtaining relevant independent advice.

Reply via email to