Hi, I'm not sure why wrap_key doesn't work here, but wey_type should solve this issue.
Evgenii вт, 31 мар. 2020 г. в 23:10, Dominik Przybysz <alien11...@gmail.com>: > Hi, > I created SQL cache, but sometimes I want to use it via javax.cache.api > and it doesn't work. > > I created cache with SQL: > > CREATE TABLE IF NOT EXISTS Person6 ( > id varchar primary key , > city_id int, > name varchar, > age int, > company varchar > ) WITH > "template=replicated,backups=1,wrap_key=false,value_type=java.util.HashMap,cache_name=Person6"; > > insert into PERSON6(ID, CITY_ID, NAME, AGE, COMPANY) values ( > '1', 1, 'TEST', 20, 'Bla' > ); > > insert into PERSON6(ID, CITY_ID, NAME, AGE, COMPANY) values ( > '2', 1, 'TEST2', 20, 'Bla 1' > ); > > Next I created client and fetching data with SqlFieldQuery works without > problems: > > SqlFieldsQuery query = new SqlFieldsQuery("SELECT * from Person6"); > FieldsQueryCursor<List<?>> cursor = cache.query(query); > > but when I tried to query the cache with get: > > IgniteCache<String, Object> cache = ignite.cache("Person6"); > System.out.println("CacheSize: " + cache.size(CachePeekMode.PRIMARY)); > System.out.println("1: " + cache.get("1")); > > I received: > > CacheSize: 2 > 1: null > > To solve it I added withKeepBinary(): > > IgniteCache<String, Object> cache = > ignite.cache("Person6").withKeepBinary(); > > and then I received valid data: > > CacheSize: 2 > 1: java.util.HashMap [idHash=660595570, hash=-1179353910, CITY_ID=1, > ID=null, NAME=TEST, AGE=20, COMPANY=Bla] > > but now I cannot add HashMap to the cache: > > Map<String, Object> value = new HashMap<>(); > value.put("ID", uuid); > value.put("CITY_ID", 1); > value.put("NAME", "c"); > value.put("AGE", 90); > value.put("COMPANY", "AAAAA"); > cache. put(uuid, value); > > throws: > > Exception in thread "main" javax.cache.CacheException: class > org.apache.ignite.IgniteCheckedException: Unexpected binary object class > [type=class > org.apache.ignite.internal.processors.cacheobject.UserCacheObjectImpl] > > and adding works only with objects created with BinaryObjectBuilder. > > Is it expected behaviour for caches String->HashMap? > > -- > Pozdrawiam / Regards, > Dominik Przybysz >