You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Anthony Hong <an...@gmail.com> on 2006/06/11 13:01:47 UTC

Does sqlmap support polymorphism in result-map

I have a set of class with generlization relationship. They are saved
in one table with a type field to sepreate which type they are.

How can I fetch them with the help of ibatis result map to construct
properly class with type field help

Say, If type = 1, then create Class A
if type = 2, then create Class B

Can this be achieved in ibatis result-map support?

Thanks in advance

-- 

Anthony Hong

Re: Does sqlmap support polymorphism in result-map

Posted by Gilles Bayon <ib...@gmail.com>.
>From unit test


<resultMap id="document" class="testdomain.Document">
    <result property="id" column="DOCUMENT_ID"/>
    <result property="title" column="DOCUMENT_TITLE"/>
    <result property="type" column="DOCUMENT_TYPE"/>
    <discriminator column="DOCUMENT_TYPE" javaType="string" >
      <subMap value="Book" resultMap="book"/>
      <subMap value="Newspaper" resultMap="news"/>
    </discriminator>
  </resultMap>

  <resultMap id="book" class="testdomain.Book" extends="document">
    <result property="pages" column="DOCUMENT_PAGENUMBER"/>
  </resultMap>

  <resultMap id="news" class="testdomain.Magazine" extends="document">
    <result property="city" column="DOCUMENT_CITY"/>
  </resultMap>

  <select id="getDocuments" resultMap="document">
    select * from DOCUMENTS
  </select>

Re: Does sqlmap support polymorphism in result-map

Posted by Anthony Hong <an...@gmail.com>.
Any example or links can be provides?
I cannot find it through ibatis developer guideline and sqlmap
document to descibe how to use it.
Thanks.

On 6/11/06, Gilles Bayon <ib...@gmail.com> wrote:
>
> Yes, use discriminator tag in Result-Map.
>
> -Gilles
>
>


-- 

Anthony Hong

Re: Does sqlmap support polymorphism in result-map

Posted by Gilles Bayon <ib...@gmail.com>.
Yes, use discriminator tag in Result-Map.

-Gilles