ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Butler <jeffgbut...@gmail.com>
Subject Re: how to map unsigned bigint in MySql to long value
Date Thu, 27 Oct 2005 16:02:53 GMT
I've tried your exact example (as close as I can replicate), and don't have
any errors - and the values comes back as expected. MySql returns a Long for
signed bigint fields, and a BigInteger for unsigned bigint fields.
 If your database field is unsigned, then you must set the type in your POJO
to "Object" and cast it yourself to BigInteger. If the database field is
signed, then either Long or long will work. I did get a weird result when I
tried the Long/unsigned combination (as expected - there is a loss of
precision in that case).
 I tried it with MySQL 5.0.15, and connector/j 3.1.11.
 HTH -
Jeff Butler
 On 10/26/05, Siming Weng <siming.weng@gmail.com> wrote:
>
> Hi,
>
> The problem still exists. Here's my situation:
>
> I have a field in table in MySQL, unsigned bigint(20) time_stamp
> I have a result class which has a member "private long timeStamp"
>
> ...
> <result property="timeStamp" column="time_stamp"/>
> ...
>
> the value in database is 1428387426 whose binary format is
> 1010101001000110111011001100010
>
> the value in my result class is 7094897110947987456 whose binary
> format is 110001001110110001000110101010100000000000000000000000000000000
>
> if I changed time_stamp to unsigned, it works fine. I've even tried
> "private Object timeStamp" but the runtime class of timeStamp is still
> java.lang.Long.
>
> Is it an issue of iBatis?
>
> On 10/26/05, Jeff Butler <jeffgbutler@gmail.com> wrote:
> > iBATIS does not have a type handler for BigInteger - because there is no
> > "getBigInteger()" method on a result set. iBATIS will call getObject()
> if
> > it doesn't know what the data type is (i.e. if you use a Map as a
> result, or
> > if the property in your result class is of type Object) - then you could
> > cast it yourself. This will mimic what you are doing in JDBC.
> >
> > Jeff Butler
> >
> >
> > On 10/26/05, Siming Weng <siming.weng@gmail.com > wrote:
> > > Hi,
> > >
> > > I'm trying to map a table field of unsigned bigint to long value in
> > > java. But it always give wrong numbers looks like being overflow. Pure
> > > JDBC code can return the correct value.
> > >
> > > JDBC documenation says RecordSet.getObject(int columnIndex) will
> > > return a java.math.BigInteger if the field is unsigned bigint. But it
> > > seems iBatis doesn't support BigInteger.
> > >
> > > did anyone experience the same problem?
> > >
> > > Cheers,
> > >
> > > Simon
> > >
> >
> >
>

Mime
View raw message