ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Duffey <tduf...@utilivisor.com>
Subject Re: Enums and iBatis - still not clear
Date Wed, 13 Jun 2007 04:58:50 GMT

On Jun 12, 2007, at 9:32 PM, Paul Benedict wrote:

> For each enum you want to write to the database, you need to write  
> yourself an iBatis type call back handler. This will translate the  
> enum to whatever data type you want (and int or a string, etc.),  
> and vice-versa.

This is more of a developer list question but is there any reason why  
we can't make iBATIS handle the simple enum case where the name maps  
directly to/from the DB automatically?  It's a major pain to write  
all these type handlers.

Tom

> Sebastian Niezgoda wrote:
>> Hello,
>>
>> I've read through archives and the wiki but I'm still not clear on  
>> how exactly to handle enums using iBatis.
>>
>> I use ant's xjc task to create objects from a database schema. The  
>> code tables become Java Enum objects such as:
>>
>> public enum MyEnum {
>>    VAL1,
>>    VAL2;
>>
>>    public String value() {
>>       return name();
>>    }
>>
>>    public static MyEnum fromValue(String v) {
>>       return valueOf(v);
>>    }
>> }
>>
>> I have a POJO, MyObject, with the following parameters:
>>
>> private String ID;
>> private MyEnum enum;
>>
>>
>> I do a simple query and in the DAO SQL I create a result map as  
>> follows:
>>
>> <resultMap id="pojoMap" class="MyObject">
>>    <result property="ID" column="ID" />
>>    <result property="enum" resultMap="MyObject.enumMap" />
>> </resultMap>
>>
>> <resultMap id="enumMap" class="MyEnum">
>>    <result property="?????" value="enum" />
>> </resultMap>
>>
>>
>> My question is - how do I map the value I retrieve from db (called  
>> enum) to the MyEnum class?
>>
>> No matter what I replace the ????? with it doesn't work and it  
>> fails with the following error:
>>
>> Cause: com.ibatis.common.beans.ProbeException: There is no  
>> WRITEABLE property named '?????'; in class 'MyEnum'
>>
>> I could create a bunch of handlers but there are many of them and  
>> since the objects are generated from the schema they can always  
>> change.  Is there an easy way to do this?
>>
>> Thanks,
>>
>> Sebastian
>>


Mime
View raw message