Cassandra: Hector, serializationException invalid stram header -
im working apache cassandra (cassandra version: 1.2.3, thrift api version: 19.35.0, cql supported versions: 2.0.0,3.0.1 (default: 3.0.1)) , hector 1.0.5.
im using following code insert , retrieve object.
string cf="user"; key="mykey"; string colname="colname"; string colvalue="colvalue"; mutator<string> mutator = hfactory.createmutator(keyspace, stringserializer.get()); mutator.insert(key, cf, hfactory.createstringcolumn(colname, colvalue)); columnquery<string, string, object> columnquery = hfactory.createcolumnquery( keyspace, stringserializer.get(), stringserializer.get(), objectserializer.get()); columnquery.setcolumnfamily(cf).setkey(key).setname(colname); queryresult<hcolumn<string, object>> r = columnquery.execute(); system.out.println("read hcolumn cassandra: " + r.get());
but following exception:
exception in thread "main" me.prettyprint.hector.api.exceptions.hectorserializationexception: java.io.streamcorruptedexception: invalid stream header: 636f6c76 @ me.prettyprint.cassandra.serializers.objectserializer.frombytebuffer(objectserializer.java:79) @ me.prettyprint.cassandra.model.hcolumnimpl.getvalue(hcolumnimpl.java:124) @ me.prettyprint.cassandra.model.hcolumnimpl.tostring(hcolumnimpl.java:202) @ java.lang.string.valueof(string.java:2854) @ java.lang.stringbuilder.append(stringbuilder.java:128) @ org.dargamenteria.tfg.texu.logic.userdaoimpl.create(userdaoimpl.java:111)
but following code works, changed objectserializer stringserializer:
mutator<string> mutator = hfactory.createmutator(keyspace, stringserializer.get()); mutator.insert(key, cf, hfactory.createstringcolumn(colname, colvalue)); columnquery<string, string, string> columnquery = hfactory.createcolumnquery( keyspace, stringserializer.get(), stringserializer.get(), stringserializer.get()); columnquery.setcolumnfamily(cf).setkey(key).setname(colname); queryresult<hcolumn<string, string>> r = columnquery.execute(); system.out.println("read hcolumn cassandra: " + r.get());
if hector serializer hierarchy, find objectserializer & stringserializer both siblings, both implementing serializer interface , extending abstractserializer class.
frombytebuffer method in stringserializer expecting string, whereas in objectserializer expecting object. , in code have defined column value string type, have use stringserializer set of code expecting string type.
Comments
Post a Comment