EHC ❯ Search fails when copyOnRead and copyOnWrite are both set
-
Bug
-
Status: Resolved
-
2 Major
-
Resolution: Fixed
-
ehcache-core
-
-
teck
-
Reporter: dhdai
-
October 19, 2012
-
0
-
Watchers: 6
-
November 07, 2012
-
October 19, 2012
Description
When copyOnRead and copyOnWrite are both set, search by value attribute fails with ClassCastException in AtributeExtractor,
Exception in thread “main” java.lang.ClassCastException: [B cannot be cast to org.sharrissf.sample.Person at org.sharrissf.sample.EhcacheSearchPlaying$NameAttributeExtractor.attributeFor(EhcacheSearchPlaying.java:200) at org.sharrissf.sample.EhcacheSearchPlaying$NameAttributeExtractor.attributeFor(EhcacheSearchPlaying.java:206) at net.sf.ehcache.search.expression.ILike.execute(ILike.java:145) at net.sf.ehcache.search.expression.And.execute(And.java:69) at net.sf.ehcache.store.MemoryOnlyStore$BruteForceSearchManager.executeQuery(MemoryOnlyStore.java:151) at net.sf.ehcache.store.AbstractStore.executeQuery(AbstractStore.java:174) at net.sf.ehcache.store.ElementIdAssigningStore.executeQuery(ElementIdAssigningStore.java:449) at net.sf.ehcache.Cache.executeQuery(Cache.java:4015) at net.sf.ehcache.CacheQuery.execute(CacheQuery.java:181) at org.sharrissf.sample.EhcacheSearchPlaying.runTests(EhcacheSearchPlaying.java:109) at org.sharrissf.sample.EhcacheSearchPlaying.main(EhcacheSearchPlaying.java:188)
To reproduce it, just take the sample code at https://github.com/sharrissf/Ehcache-Search-Sample and set CacheConfiguration cacheConfig.copyOnRead(true).copyOnWrite(true).
It seems Element.getValue() or getObjectValue() always returns byte[] instead of the original value type.
It works fine if either copyOnRead or copyOnWrite is not set.
Comments
Ludovic Orban 2012-10-19
Tim Eck 2012-10-19
should be resolved in ehcache 2.6.2
As a workaround, you can configure the SerializationCopyStrategy on your searchable caches:
This should prevent the problem from occurring.