BigMemory 4.3.7 | Product Documentation | BigMemory Max Configuration Guide | Working with Transactions | Implementing an Element Comparator
 
Implementing an Element Comparator
For all transactional caches, the atomic methods Cache.removeElement(Element element) and Cache.replace(Element old, Element element) must compare elements for the atomic operation to complete. This requires all objects stored in the cache to override equals() and hashCode().
If overriding these methods is not desirable for your application, a default comparator is used (net.sf.echache.store.DefaultElementValueComparator). You can also implement a custom comparator and specify it in the cache configuration with <elementValueComparator>:
<cache name="com.my.package.Foo"
maxEntriesLocalHeap="500"
eternal="false"
copyOnRead="true"
copyOnWrite="true"
consistency="strong"
transactionalMode="xa">
<elementValueComparator class="com.company.xyz.MyElementComparator" />
<persistence strategy="distributed"/>
<terracotta />
</cache>
Custom comparators must implement net.sf.ehcache.store.ElementValueComparator.
A comparator can also be specified programmatically.