Reputation: 71
I am trying to insert some java object as a list into cassandra. I have a serializable java class I insert them as :
public void storeFeatures(java.util.Vector features){
java.util.UUID uuid = java.util.UUID.randomUUID();
java.util.List<ByteBuffer> ls=new java.util.ArrayList<ByteBuffer>();
for(int i=0;i<features.size();i++) {
my.package.Feature f=(my.package.Feature)features.elementAt(i);
byte[]b=(new ObjectToBytes()).getBytes(f);
ls.add(java.nio.ByteBuffer.wrap(b));
}
session.execute("INSERT INTO mytable ( id, features) values ( ?, ? )", uuid, ls);
}
But, somehow I can not retrieve them with
public java.util.List getFeatures(){
java.util.List<ByteBuffer> ret=null;
ResultSet rows = session.execute("SELECT * FROM imgs limit 10");
for(Row row: rows){
row.getBytes("features");
ret=row.getList("features",java.nio.ByteBuffer.class);
}
return ret;
}
I get
com.datastax.driver.core.exceptions.InvalidTypeException: Column features is of type list<blob>
at com.datastax.driver.core.ColumnDefinitions.checkType(ColumnDefinitions.java:291)
How can I retrieve list < blob > types as list < ByteBuffer >?
Upvotes: 1
Views: 2481
Reputation: 3374
To leave an answer: there was unnecessary call to row.getBytes("features");
which caused the error
Upvotes: 2