You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Adrian Crum <ad...@sandglass-software.com> on 2015/03/20 19:09:01 UTC
GenericPK and EntityCache
I just discovered a serious flaw in the PK cache (EntityCache.java):
GenericPK is used as a cache key. This is bad for two reasons:
1. GenericPK is mutable and its hash code changes over time. It can be
made immutable before adding it to the cache.
2. The equals method is implemented by the GenericEntity super class -
which compares ALL fields, not just primary key fields. So, the PK cache
can contain multiple versions of the same PK.
I'm trying to decide how to fix this. My preferences would be to
override equals() and hashCode() in GenericPK so that it behaves as
expected, but that might break a lot of code. The other option would be
create a String cache key from the GenericPK instance.
--
Adrian Crum
Sandglass Software
www.sandglass-software.com
Re: GenericPK and EntityCache
Posted by Adrian Crum <ad...@sandglass-software.com>.
Okay, #2 is not a problem. When the GenericPK instance is created it
only contains pk fields. I still need to fix #1.
Adrian Crum
Sandglass Software
www.sandglass-software.com
On 3/20/2015 6:09 PM, Adrian Crum wrote:
> I just discovered a serious flaw in the PK cache (EntityCache.java):
> GenericPK is used as a cache key. This is bad for two reasons:
>
> 1. GenericPK is mutable and its hash code changes over time. It can be
> made immutable before adding it to the cache.
> 2. The equals method is implemented by the GenericEntity super class -
> which compares ALL fields, not just primary key fields. So, the PK cache
> can contain multiple versions of the same PK.
>
> I'm trying to decide how to fix this. My preferences would be to
> override equals() and hashCode() in GenericPK so that it behaves as
> expected, but that might break a lot of code. The other option would be
> create a String cache key from the GenericPK instance.
>