[hibernate-dev] Mutable natural key caching?
Elias Ross
genman at noderunner.net
Tue Sep 16 13:03:14 EDT 2008
I've been looking to optimize the caching of an application which uses
a mutable natural key, an account phone number.
Hibernate does not yet support optimized caching of
@NaturalId(mutable=false), because of how the current natural ID
relies on immutable IDs. The caching associates a QueryKey -> results
and it's impossible to evict the QueryKey since the natural keys are
embedded in it.
One solution I considered was to create an association between a set
of natural ID values and "QueryKey". When a query is made with mutable
natural keys, an association would be made. This could be done within
"StandardQueryCache." And then when an entity is updated or removed,
if there are mutable natural keys, Hibernate could locate the query
and remove it as well. I'm not sure how I could implement this part.
I'm guessing I'd have to add a method to QueryCache to do the removal.
public interface QueryCache {
...
public void remove(NaturalIdAssocation nia) throws HibernateException;
}
public class NaturalIdAssociation implements Serializeable {
Type type;
Set<Object> keys;
}
Actually, thinking this over, having this removal operation would fix
some other issues when non-mutable natural id entities are removed.
For instance, HHH-3478, a problem found using EntityManager and
natural IDs.
Thoughts?
More information about the hibernate-dev
mailing list