Long and long do not work as primary key
I have tried to use a Long type as a primary key ( ie @Id) - as well as long and on calling em.persist(object) the following exception is thrown:
Environment :
Kundera 2.0.7 Cassandra 1.1.2
Caused by: org.scale7.cassandra.pelops.exceptions.InvalidRequestException: Expected 8 or 0 byte long (18) at org.scale7.cassandra.pelops.exceptions.IExceptionTranslator$ExceptionTranslator.translate(IExceptionTranslator.java:47) at org.scale7.cassandra.pelops.Operand.tryOperation(Operand.java:113) at org.scale7.cassandra.pelops.Mutator.execute(Mutator.java:93) at org.scale7.cassandra.pelops.Mutator.execute(Mutator.java:63) at com.impetus.client.cassandra.pelops.PelopsClient.onPersist(PelopsClient.java:923) at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:84) at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:180) at com.impetus.kundera.graph.Node.flush(Node.java:522) at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:367) at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:154) at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:279) ... 49 more Caused by: InvalidRequestException(why:Expected 8 or 0 byte long (18)) at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:20253) at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78) at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:922) at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:908) at org.scale7.cassandra.pelops.Mutator$1.execute(Mutator.java:88) at org.scale7.cassandra.pelops.Mutator$1.execute(Mutator.java:84) at org.scale7.cassandra.pelops.Operand.tryOperation(Operand.java:86) ... 58 more
If I switch to String as the PK, it works OK.
I'm using the following in persistence.xml:
Please have a look at : https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/datatypes/StudentCassandra.java
And
https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/datatypes/StudentCassandraTest.java
Have a look at StudentCassandraTest.java for column family creation script to validate your db script, entity defintion and opreations.
Also you could try with:
"kundera.ddl.auto.prepare" value="create" to have a look on created column family to validate with your one.
I was using kundera.dll.auto.prepare, actually I was using update not create, but I don't think that will make any difference.
The col family definition looks ok -
When I take StudentCassandraTest.java and produce a c.f. creation script using the one that is contained, I get the following:
create column family thing with comparator=AsciiType and key_validation_class=LongType and column_metadata=[{column_name: title, validation_class:UTF8Type, index_type: KEYS}];
When I describe the one created by kundera.ddl.auto.prepare I get:
describe thing;
ColumnFamily: thing
Key Validation Class: org.apache.cassandra.db.marshal.LongType
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.BytesType
GC grace seconds: 864000
Compaction min/max thresholds: 4/32
Read repair chance: 0.1
DC Local Read repair chance: 0.0
Replicate on write: true
Caching: KEYS_ONLY
Bloom Filter FP chance: default
Built indexes: []
Column Metadata:
Column Name: title (7469746c65)
Validation Class: org.apache.cassandra.db.marshal.UTF8Type
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
Compression Options:
sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor
Not sure.. why is it not working.. Though StudentCassandraTest is working fine in test suite.
From: dstrawson [email protected] To: Vivek Mishra [email protected] Sent: Saturday, July 28, 2012 10:53 PM Subject: Re: [Kundera] Long and long do not work as primary key (#91)
I was using kundera.dll.auto.prepare, actually I was using update not create, but I don't think that will make any difference.
The col family definition looks ok -
When I take StudentCassandraTest.java and produce a c.f. creation script using the one that is contained, I get the following:
create column family thing with comparator=AsciiType and key_validation_class=LongType and column_metadata=[{column_name: title, validation_class:UTF8Type, index_type: KEYS}];
When I describe the one created by kundera.ddl.auto.prepare I get:
describe thing; ColumnFamily: thing Key Validation Class: org.apache.cassandra.db.marshal.LongType Default column value validator: org.apache.cassandra.db.marshal.BytesType Columns sorted by: org.apache.cassandra.db.marshal.BytesType GC grace seconds: 864000 Compaction min/max thresholds: 4/32 Read repair chance: 0.1 DC Local Read repair chance: 0.0 Replicate on write: true Caching: KEYS_ONLY Bloom Filter FP chance: default Built indexes: [] Column Metadata: Column Name: title (7469746c65) Validation Class: org.apache.cassandra.db.marshal.UTF8Type Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy Compression Options: sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor
Reply to this email directly or view it on GitHub: https://github.com/impetus-opensource/Kundera/issues/91#issuecomment-7335646
well, my simplified example from issue-90 shows this issue, if you want to look at it. I will study StudentCassandraTest and see if I can see anything I've done wrong.
Thanks. i will have a look and get this working ..
Hi, I have verified this issue, I am working on it.
It will work fine 2.0.7 for long data types, if you define your Key Validation Class as org.apache.cassandra.db.marshal.BytesType. in place of Key Validation Class: org.apache.cassandra.db.marshal.LongType
However, i need to get it working for LongType as well.
Hi Daniel, This script should work for you as a workaround:
create column family thing with comparator=UTF8Type and key_validation_class=BytesType and column_metadata=[{column_name: title, validation_class:UTF8Type, index_type: KEYS}];
I will post an update once get it done for other types for key_validation_class.
Thanks - that's the way I've done it and it seems to work ok. I'm dropping my keyspace, letting auto.ddl. recreating, dumping it from cassandra cli and then making above edits, then re-importing and turning off auto ddl creation.
Thanks for your help sorting out both these issues - I hope you don't mind me logging other issues as I find them, I will re-create them in the test example as I go.
-Daniel
That's absolutely fine :)
-Vivek
Closing on this, as support on all data type in place with proper junits.
-Vivek