Although nobody responded to my post I guess this bug still exists in
Torque.
The problem is the way org.apache.torque.om.NumberKey instantiates a
BigDecimal for a long key - see Sun's description of the reasons for
this behavior - not a bug in their view :
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4114020

I fixed NumberKey.java by replacing:
  public NumberKey(long key)
    {
        this.key = new BigDecimal(key);
    }
    
    With:
      public NumberKey(long key)
    {
        this.key = BigDecimal.valueOf(key);
    } 

as recommended in the above Sun link.
To test this you can use:
public static void main(String[] args) 
{
        long pk = Long.parseLong("22620000000000031");
        SimpleKey sk = SimpleKey.keyFor(pk);
        System.out.print(sk.getValue());
}

Cheers Guy

On Wed, 2007-02-21 at 15:30 -0500, Guy Galil wrote:
> We are using an old version of Torque - Torque 3.0.2 for a long time
> now.
> We recently encountered a strange behavior of the retrieveByPK method:
> we have a column defined as -
> <table name="MYTABLE_LOG" description="Log of dropped and rejected
> constructs" idMethod="native">
>     <column 
>       name="MYTABLE_LOG_ID" 
>       required="true" 
>       primaryKey="true" 
>       type="BIGINT" 
>       autoIncrement="true"/>
> 
> 
> ....
> 
> 
> 
> The generated sql is -
> drop table if exists MYTABLE_LOG;
> 
> CREATE TABLE MYTABLE_LOG
> (
>                     MYTABLE_LOG_ID BIGINT NOT NULL AUTO_INCREMENT,
> ....
> 
> the mysql table is actually created with the column type
>  bigint(20)
> 
> Id values in the database get to be big.
> 
> The problem is when using retrievebypk and the id passed is long. The
> method in the base class looks like:
>     public static MytableLog retrieveByPK(long pk)
>         throws TorqueException
>     {
>         return retrieveByPK(SimpleKey.keyFor(pk));
>     }
> 
> looking at the values in a debugger we see:
> pk = 22620000000000031
> SimpleKey.keyFor(pk) = 22620000000000032
> and
> return retrieveByPK(SimpleKey.keyFor(pk)) either fails fails (failed to
> retrieve one
> row...) if the record is not found or returns the wrong record (see it
> passes the id + 1)
> 
> This problem did not occur when our keys were of type integer.
> 
> Any help will be appreciated
> Guy
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to