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 Andreas Prudzilko <ap...@welho.com> on 2006/10/29 20:50:47 UTC

Persitence Interface

Hello,

I have one interface Template and several Subclasses for it, 
AbstractTemplate, PageTemplate and so on.
They are all persisted in the same table though, distinguished by a 
column called "type".

I was wondering how I can tell ibatis to create instances of the right 
classes based on the column value.

My guess was creating a resultObjectFactory. But I can't find any good 
documentation on how to do this.

Any ideas?

- Andreas

Re: Persitence Interface

Posted by Clinton Begin <cl...@gmail.com>.
I can't remember, but are the discriminator features documented anywhere?
Wiki or otherwise?

Cheers,
Clinton


On 10/29/06, Larry Meadors <lm...@apache.org> wrote:
>
> Look into using a discriminator - they work great for what you are
> describing.
>
> Here is a realllly terse example:
>
> <discriminator javaType="string" column="type">
>     <subMap value="Cash" resultMap="rmCash" />
>     <subMap value="Pledge" resultMap="rmPledge" />
>     <subMap value="PayPalDirPay" resultMap="rmPayPalDirPay" />
>     <subMap value="PayPalExpChkout" resultMap="rmPayPalExpChkout" />
> </discriminator>
>
> It looks at the type column, and based on the value, uses a different
> result map.
>
> Neat, huh?
>
> Larry
>
>
> On 10/29/06, Andreas Prudzilko <ap...@welho.com> wrote:
> > Hello,
> >
> > I have one interface Template and several Subclasses for it,
> > AbstractTemplate, PageTemplate and so on.
> > They are all persisted in the same table though, distinguished by a
> > column called "type".
> >
> > I was wondering how I can tell ibatis to create instances of the right
> > classes based on the column value.
> >
> > My guess was creating a resultObjectFactory. But I can't find any good
> > documentation on how to do this.
> >
> > Any ideas?
> >
> > - Andreas
> >
>

Re: Persitence Interface

Posted by Larry Meadors <lm...@apache.org>.
Look into using a discriminator - they work great for what you are describing.

Here is a realllly terse example:

<discriminator javaType="string" column="type">
    <subMap value="Cash" resultMap="rmCash" />
    <subMap value="Pledge" resultMap="rmPledge" />
    <subMap value="PayPalDirPay" resultMap="rmPayPalDirPay" />
    <subMap value="PayPalExpChkout" resultMap="rmPayPalExpChkout" />
</discriminator>

It looks at the type column, and based on the value, uses a different
result map.

Neat, huh?

Larry


On 10/29/06, Andreas Prudzilko <ap...@welho.com> wrote:
> Hello,
>
> I have one interface Template and several Subclasses for it,
> AbstractTemplate, PageTemplate and so on.
> They are all persisted in the same table though, distinguished by a
> column called "type".
>
> I was wondering how I can tell ibatis to create instances of the right
> classes based on the column value.
>
> My guess was creating a resultObjectFactory. But I can't find any good
> documentation on how to do this.
>
> Any ideas?
>
> - Andreas
>