I need to write a Java object to Cassandra using its Hector API. I have a Set object which I have tried to serialize and then use it in Hector's insert() on a mutator for the column family. I keep getting errors that the object is not serializable. I could not find any documentation for this use case.
1 Answers
1
votes
I was able to add a Java object to a Cassandra Column in the following way:
StringSerializer stringSerializer = StringSerializer.get();
ObjectSerializer flatten=ObjectSerializer.get();
Mutator<String> mutator = HFactory.createMutator (keySpace, stringSerializer);
HColumn<String, Object> column=HFactory.createColumn ("1", object1, stringSerializer,flatten);
mutator.insert ("pages",COLUMN_FAMILY, column);
Here, object1 is the object that I want to write to Cassandra. keySpace is of type me.prettyprint.hector.api.Keyspace, "1" is the column name, "pages" is the row key and COLUMN_FAMILY is a String stating the name of the Column Family. I was making a mistake in serializing the object first and then writing into insert() while that is not required.