Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 42423 invoked from network); 13 Jun 2007 05:00:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Jun 2007 05:00:54 -0000 Received: (qmail 52119 invoked by uid 500); 13 Jun 2007 05:00:51 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 52100 invoked by uid 500); 13 Jun 2007 05:00:51 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 52089 invoked by uid 99); 13 Jun 2007 05:00:51 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jun 2007 22:00:51 -0700 X-ASF-Spam-Status: No, hits=2.1 required=10.0 tests=HTML_MESSAGE,HTML_TAG_EXIST_TBODY X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [216.136.66.10] (HELO mail.capital-internet.net) (216.136.66.10) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jun 2007 22:00:46 -0700 Received: from [192.168.11.2] (CPE-70-94-36-108.wi.res.rr.com [70.94.36.108]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.capital-internet.net (Postfix) with ESMTP id D43DCAE77AE for ; Wed, 13 Jun 2007 00:00:25 -0500 (CDT) Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: <466F5723.7090609@apache.org> References: <1181651922.5490.3.camel@B-0459> <466F5723.7090609@apache.org> Content-Type: multipart/alternative; boundary=Apple-Mail-6--607415578 Message-Id: From: Tom Duffey Subject: Re: Enums and iBatis - still not clear Date: Tue, 12 Jun 2007 23:58:50 -0500 To: user-java@ibatis.apache.org X-Mailer: Apple Mail (2.752.3) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-6--607415578 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed 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: >> >> >> >> >> >> >> >> >> >> >> >> 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 >> --Apple-Mail-6--607415578 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=ISO-8859-1
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? =A0It'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=3D"pojoMap" = class=3D"MyObject">
   <result property=3D"ID" column=3D"ID" =
/>
   <result property=3D"enum" resultMap=3D"MyObject.enumMap" />
</resultMap>

<resultMap id=3D"enumMap" class=3D"MyEnum">
   <result property=3D"?????" value=3D"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.=A0 Is = there an easy way to do this?

Thanks,

Sebastian
= =

=

= --Apple-Mail-6--607415578--