commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell" <flame...@gmail.com>
Subject Re: BeanUtils
Date Thu, 09 Nov 2006 17:03:53 GMT
On 11/9/06, Qin Ding <QDING@transunion.com> wrote:
> in database, 'rqst_sts_cde' is defined as smallint.  I don't know what
> these 'Short' or 'Integer' come from.  I guess from build-in converter.
> What is 'smallint' supposed to convert to?  And how to override the
> build-in converter.  Please help.

Digging into the source, it looks like the Short is coming from the
DB2 JDBC driver when BeanUtils asks it what type the DB2 smallint
column should be represented as as a Java object.

Line 169 ot JDBCDynaClass (in trunk):

            className = metadata.getColumnClassName(i);

When BeanUtils then gets the data, it assumes that the object it gets
via ResultSet.getObject (line 232 of RowSetDynaClass) is of the type
that the database is advising it to use. I'm not sure if the JDBC spec
intends for this to be done, but I suspect so.

So I think this is a bug in the DB2 JDBC driver - it's not returning
the type of Object it advises a client to create.

Alfredo has the correct and easiest technical work-around - find a
type that works with the JDBC driver at the database level - 'int'
seems like a good choice. That might be hard to do if you're not in
control of the schema though.

Another work-around would be to extend RowSetDynaClass and override
the copy(ResultSet) method to have a hack to get around this (by
forcing the Integer into a Short when the underlying type is a Short),
or more painfully, overriding createDynaBean() to return a dynabean
that doesn't use Shorts but uses Integers instead. That involves
overriding other methods though.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message