Hi Gerhard and Nikolaus,
> hashCode() as keys into a Hashtable. Since hash codes of different objects can
> be equal, this sooner or later had to fail.
>
sorry this was my fault I only think about PK values of type Integer (here #hashCode and #equals has same result) and best performance, completely ignoring Long, String,...
> If you are using the default cache setting, you can simply change the buildKey
> method to return an Object, namely oid itself. If you are using one of the other
> options I can post a utility class that combines several objects to a single
> hash table key and you can use this in your ObjectCache. Let me know.
if you send me your utility class I will integrate it in CVS trunk/branch
Sorry again, think I should take a java beginner's course.
regards, Armin
Gerhard Grosse wrote:
Hi Nikolaus,
This is copied from ObjectCacheDefaultImpl:
private Integer buildKey(Identity oid) { int key = 0; switch(cachingKeyType) { case 0: key = oid.hashCode(); break; case 1: key = new HashCodeBuilder().append(broker.getPBKey().getAlias().hashCode()).append(oid.hashCode()).toHashCode(); break; case 2: key = new HashCodeBuilder().append(broker.getDescriptorRepository().hashCode()).append(oid.hashCode()).toHashCode(); break; case 3: key = new HashCodeBuilder().append(broker.getDescriptorRepository().hashCode()).append(broker.getPBKey().getAlias().hashCode()).append(oid.hashCode()).toHashCode(); break; default: throw new OJBRuntimeException("Unexpected error, 'cacheType ="+cachingKeyType+"' was not supported"); } return new Integer(key); }
It is interesting that someone finally discovered this bug in action. Indeed OJB's latest object cache implementations use an object based on the PK's hashCode() as keys into a Hashtable. Since hash codes of different objects can be equal, this sooner or later had to fail.
We are using own ObjectCache implementations for some other reasons but stumbled about this when adapting our caches to version 1.0.1. I always wanted to post something about this problem to the list, but, alas, I forgot about it.
If you are using the default cache setting, you can simply change the buildKey method to return an Object, namely oid itself. If you are using one of the other options I can post a utility class that combines several objects to a single hash table key and you can use this in your ObjectCache. Let me know.
But of course I hope someone of the OJB gurus will fix this in the official code...
Gerhard
On Thu, 18 Nov 2004 15:55:41 +0100, [EMAIL PROTECTED] wrote:
Hi,
i am using OJB since 1 and 1/2 years. This week i tried to move from Version 1.0 to 1.0.1.
I detected the following problem:
I have two objects of two different classes (aClass and bClass) with the same base class. I use strings as primary keys. Object a has the string 'WR' as pk, object b the string 'X3'. If i first search for object of aClass with objectId = WR and then for object of bClass with objectID = X3, i retrieve the object a two times.
The reason seems to be that both strings are mapped two the same Integer in org.apache.ojb.broker.Identity.hashCode()
This behaviour of the Object Cache was not in OJB 1.0.
Is this a known problem in OBJ 1.0.1?
Best regards
Nikolaus Bininda.
--------------------------------------------------------------------- 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]
