You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Dovlecel Alexandru Ovidiu <al...@siemens.com> on 2004/05/04 16:05:57 UTC
RE: hashCode/equals contract broken in BaseObject
You can use torque objects as hash keys with one condition:
all the keys in the hashtable must be instances of the same torque class.
Then you will not have any inconsistency.
-----Original Message-----
From: Shevek [mailto:shevek@anarres.org]
Sent: Tuesday, May 04, 2004 4:07 PM
To: Apache Torque Users List
Subject: hashCode/equals contract broken in BaseObject
hashCode and equals in BaseObject rely only on the primary key. This
breaks horribly (violates the general contract of hashCode()/equals()) if
you compare two objects of different classes.
It MUST compare ob.getClass() as well as ob.getPrimaryKey() and include
ob.getClass().hashCode() in its hashCode() [by xor?] [or something
equivalent].
No doubt the reason for this violation is noted in the FAQ, but it seems
worth noting as a serious bug since it means I can't use Torque objects as
hash keys.
S.
--
Shevek http://www.anarres.org/
I am the Borg. http://www.gothnicity.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
RE: hashCode/equals contract broken in BaseObject
Posted by Shevek <sh...@anarres.org>.
On Tue, 4 May 2004, Dovlecel Alexandru Ovidiu wrote:
> You can use torque objects as hash keys with one condition:
>
> all the keys in the hashtable must be instances of the same torque class.
> Then you will not have any inconsistency.
I know this. However, this is in violation of the equals() contract and
causes much breakage. equals() should return true if and only if the
objects are equal. I have a requirement to mix class types. I have
suggested a fix for this: use
getClass().hashCode() ^ key.hashCode()
instead of
key.hashCode()
Then the whole world will work as intended again.
S.
> -----Original Message-----
> From: Shevek [mailto:shevek@anarres.org]
> Sent: Tuesday, May 04, 2004 4:07 PM
> To: Apache Torque Users List
> Subject: hashCode/equals contract broken in BaseObject
>
>
> hashCode and equals in BaseObject rely only on the primary key. This
> breaks horribly (violates the general contract of hashCode()/equals()) if
> you compare two objects of different classes.
>
> It MUST compare ob.getClass() as well as ob.getPrimaryKey() and include
> ob.getClass().hashCode() in its hashCode() [by xor?] [or something
> equivalent].
>
> No doubt the reason for this violation is noted in the FAQ, but it seems
> worth noting as a serious bug since it means I can't use Torque objects as
> hash keys.
>
> S.
>
>
--
Shevek http://www.anarres.org/
I am the Borg. http://www.gothnicity.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org