2

I created a composite primary key column family in cassandra

CREATE TABLE rMessage ( Key varchar,msg_id varchar, msg blob, PRIMARY KEY(key,msg_id) );

I am trying to create a record via Fluent cassandra api.

       string key = "cat1"; 
       string id = "2";

       CompositeType compositeKey = new CompositeType<FluentCassandra.Types.AsciiType, FluentCassandra.Types.AsciiType>(key,id);
       FluentColumnFamily record = ColumnFamily.CreateRecord(compositeKey.ToString());
       dynamic r = record.AsDynamic();
       r.msg = blob;
       record.Columns[0].ColumnTimeUntilDeleted = diff;
       Context.Attach(record);                
       Context.SaveChanges();

The above code return error "Not enough bytes to read value of component 0". I couldn't figure out why.

I tried the below approach but still getting the same error "Not enough bytes to read value of component 0".

var blob = CassandraBinaryFormatter.Serialzie(value);
            var compositeKey = new CompositeType<FluentCassandra.Types.UTF8Type, FluentCassandra.Types.UTF8Type>(key, value.ID.ToString());
            FluentColumnFamily record = ColumnFamily.CreateRecord(key); 
            record[compositeKey.ToString()] = blob;
            Context.Attach(record);
            Context.SaveChanges();

Thanks for help.

Saul Dolgin
  • 8,624
  • 4
  • 37
  • 43
Vytheese
  • 101
  • 1
  • 11
  • 1
    You would be much better off using CQL. Is there a reason why you can't? – Richard Oct 08 '13 at 12:40
  • Thanks Richard. I don't know how to store a blob(hex) type using CQL Moreover I like to stick with fluent object api. – Vytheese Oct 08 '13 at 13:43
  • I think Fluent supports CQL; CQL is now the recommended interface. You can insert blobs using hex encoding. – Richard Oct 08 '13 at 13:52

0 Answers0