Return-Path: Delivered-To: apmail-incubator-ibatis-user-java-archive@www.apache.org Received: (qmail 76111 invoked from network); 6 May 2005 16:19:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 May 2005 16:19:54 -0000 Received: (qmail 45084 invoked by uid 500); 6 May 2005 16:09:26 -0000 Delivered-To: apmail-incubator-ibatis-user-java-archive@incubator.apache.org Received: (qmail 45056 invoked by uid 500); 6 May 2005 16:09:25 -0000 Mailing-List: contact ibatis-user-java-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: ibatis-user-java@incubator.apache.org List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list ibatis-user-java@incubator.apache.org Received: (qmail 44974 invoked by uid 99); 6 May 2005 16:09:24 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of brandon.goodin@gmail.com designates 64.233.170.195 as permitted sender) Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.195) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 06 May 2005 09:09:24 -0700 Received: by rproxy.gmail.com with SMTP id c16so611726rne for ; Fri, 06 May 2005 09:06:36 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tap0mHVjEgwmlnFogtih1NVCDwh7NHsJ96/c+IDsITpF+ymdzJoi/ALc1Wb0fYqZ2xorT15dT4ufMTOoU2PMxhaDgXh4AkJHI/AHfhdKYt/CixBIYDynJ4T9gwY48teNzBnwEUs3nCeNu1kI+v7lSLEO7jTmVIOG6oJ6HFqnQ/M= Received: by 10.38.90.57 with SMTP id n57mr62452rnb; Fri, 06 May 2005 09:06:36 -0700 (PDT) Received: by 10.38.74.62 with HTTP; Fri, 6 May 2005 09:06:36 -0700 (PDT) Message-ID: <2fe5ef5b05050609067dabb29f@mail.gmail.com> Date: Fri, 6 May 2005 10:06:36 -0600 From: Brandon Goodin Reply-To: Brandon Goodin To: ibatis-user-java@incubator.apache.org Subject: Re: Re: struts vs ibatis - Integer type In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Your problem is not ibatis. Your problem is how BeanUtils within Struts translates an empty request parameter into an Integer property on your bean. I would handle this issue on the Struts layer. You can handle it either in your action form with a setter that receives a string and sets the value into your bean or you can write a custom Converter for BeanUtils. I recommend that you post this question to the Struts list. Brandon On 5/6/05, Lieven De Keyzer wrote: > >The only way to make that "clean" is to push the translation effort > >into your ActionForm and nest your real beans in the ActionForm. you > >would then have a String value that you convert and set into your > >nested bean. The other option is to write a different BeanUtils > >Converter implementation for numerics and register it > >(http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/bean= utils/ConvertUtils.html#register(org.apache.commons.beanutils.Converter,%20= java.lang.Class). >=20 > I like this second approach because I presume that in this case, all INTE= GER > columns will be set to NULL if no value is provided. I just don't see why= an > empty INTEGER column should be 0. > But how would I approach this problem? First rewrite the Jakarata commons > converter, and then recompile the iBatis classes with these commons class= es? >=20 > > > >I would personally avoid cluttering up your domain bean with faux > >setters and getters. > > > >Brandon > > > >On 5/2/05, Darek Dober <[EMAIL PROTECTED]> wrote: > >> Hi, I hava a table 'users' with column dept_id (id of department i= n > >>departments > >>table) This column is optional. That means the operator doesn't have = to > >>assign > >>inserted user to any department. If I have bean: public class UserB= ean > >>{ Integer departmentId; .... } struts will make automatic > >>conversion of type. So departmentId will be set > >>to 0, if I don't set any of department. That's a cheat, because, I don= 't > >>want to to have a department with id equals to 0, it should be NULL. = On > >>the other hand, when I implement departmentId as String, struts act > >>correctly. But while inserting record to the database, I get an error s= th > >>like this: database column dept_id is type of bigint, inserted value is > >>type of > >varchar. > >> I have the solution: departmentId is type of String, but for ibatis = I > >>have > >>the other metod getDepartmentIdAsInteger which return Integer or null i= f > >>value is empty. It works, but i don't like this. Is there any cleaner > >>solution for this. I looked into jpetstore, but there > >>were columns of type varchar. Rest of them was mendatory. I cannot use > >>columns of type varchar as foreign keys. Usage: .... VALUES( > >> #departmentId:INTEGER#, > >>.... doesn't help if departmentId is String Any ideas? Darek >=20 >