ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Darek Dober" <doover...@op.pl>
Subject Re: re: struts vs ibatis - Integer type
Date Thu, 05 May 2005 13:40:17 GMT
Registration my own implementation of converter is not a good choice,
because I want to treat only particular columns in that way, and converter
would treat
all integer types in the same way (I could be wrong:)

Nest my real bean is the best solution to make that "clean", however I
decided to solve this problem on database side.

If you notice, you would have the same problem with dates. If you want to
validate them, and keep invalid data to correct them, you have to keep them
as String ( I also could be wrong here:)

The easiest and most painless method for me, was to use database functions:
For example:
In postgresql you can use function TO_DATE(), or just use expression like
this: #deptId:INTEGER#::integer, which shows the clue to convert type on
database side:

SELECT '123'::integer, convert number 123 to integer type.

In Oracle there are also functions like this: TO_DATE, TO_NUMBER, and so on.

That's the way I did it

Darek Dober

----- Original Message ----- 
From: "Lieven De Keyzer" <lieven_dekeyzer@hotmail.com>
To: <dooverone@op.pl>
Sent: Thursday, May 05, 2005 3:14 PM
Subject: Re: re: struts vs ibatis - Integer type

> Where you able to use this advice? I'm kind of in same situation and
> to know if you could solve it this way.
> >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
> >
> >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 in
> >>departments
> >table)
> >>  This column is optional. That means the operator doesn't have to
> >>inserted user to any department.   If I have bean:   public class
> >>{     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
> >>want to to have a department with id equals to 0, it should be NULL.
> >>the other hand, when I implement departmentId as String, struts act
> >>correctly. But while inserting record to the database, I get an error
> >>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 if
> >>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

View raw message