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 Stephen Friedrich <st...@fortis-it.eu> on 2010/01/18 12:50:32 UTC

enums as ordinals?

By default iBATIS expects enums to be stored in the DB using the enum _names_.
I am working with a legacy DB where the enum's ordinal is stored instead.

On a global level I managed to do this by patching the default EnumTypeHandler.

The only alternative that I currently see is to write a specific type handler
for each single enum used in the project. This can't really be the ultimate
solution.

Is there a better solution that I have missed so far?
I can't register a typehandler for the "Enum" base class, because iBATIS only ever
compares to the concrete class.

Shouldn't there be a built-in, quick way to configure either ordinal or name
on a mapper level?

Re: enums as ordinals?

Posted by Ed Stafford <wa...@carbonsixty.co.uk>.
I wrote a generic EnumTypeHandler some time ago which made things quite a
bit easier. I don't have access to the source right now but I'll try to dig
it out this evening if needed, it's fairly basic and straightforward (and I
think even based off some protoype handler I found somewhere else).

Otherwise I could never think of another way of doing it. I think overall
though it is a nice way to abstract out the handling of custom types, even
if Enums could be considered first class they do afford some magic that
would be difficult to handle in a standard way.

Cheers,
-Ed

2010/1/18 Stephen Friedrich <st...@fortis-it.eu>

>  By default iBATIS expects enums to be stored in the DB using the enum
> _names_.
>
> I am working with a legacy DB where the enum's ordinal is stored instead.
>
>
>
> On a global level I managed to do this by patching the default
> EnumTypeHandler.
>
>
>
> The only alternative that I currently see is to write a specific type
> handler
>
> for each single enum used in the project. This can't really be the ultimate
>
>
> solution.
>
>
>
> Is there a better solution that I have missed so far?
>
> I can't register a typehandler for the "Enum" base class, because iBATIS
> only ever
>
> compares to the concrete class.
>
>
>
> Shouldn't there be a built-in, quick way to configure either ordinal or
> name
>
> on a mapper level?
>