"Not enough bytes to read value of component 0" with regular key
My schema: CREATE TABLE orders ( unique_id varchar PRIMARY KEY, account varchar, );
My code:
@Entity
@Table(name = "orders", schema = "data_test@simple")
public class SimpleOrder {
@Id
@Column(name = "unique_id")
private String uniqueId;
@Column(name="account")
private String account;
public SimpleOrder() {
}
public SimpleOrder(String uniqueId, String account) {
this.uniqueId = uniqueId;
this.account = account;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("Order {").append("\n");
b.append("\t").append("Unique ID = ").append(uniqueId).append("\n");
b.append("\t").append("Account = ").append(account).append("\n");
b.append("}");
return b.toString();
}
public static void main(String[] args) {
String uniqueId = "unique-id-1";
String account = "Account1";
SimpleOrder order;
order = new SimpleOrder(uniqueId, account);
System.out.println(order);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("simple");
EntityManager em = emf.createEntityManager();
em.persist(order);
em.flush();
String jpaQuery = "SELECT o from Order o";
Query query = em.createQuery(jpaQuery);
@SuppressWarnings("unchecked")
Collection<SimpleOrder> list = query.getResultList();
for(SimpleOrder o : list) {
System.out.println(o);
}
em.close();
emf.close();
}
}
My dependencies:
This is a very simple example. I'm not sure what I'm doing wrong. This is the result I'm getting:
Exception in thread "main" com.impetus.kundera.KunderaException: org.scale7.cassandra.pelops.exceptions.InvalidRequestException: Not enough bytes to read value of component 0
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:208)
at com.wedbush.model.SimpleOrder.main(SimpleOrder.java:61)
Caused by: org.scale7.cassandra.pelops.exceptions.InvalidRequestException: Not enough bytes to read value of component 0
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:527)
at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:83)
at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:193)
at com.impetus.kundera.graph.Node.flush(Node.java:525)
at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:411)
at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:169)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:202)
... 1 more
Caused by: InvalidRequestException(why:Not enough bytes to read value of component 0)
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)
... 10 more
Let me know if you know what I'm doing wrong! Thanks.
I believe column family "orders" belongs to "data_test" keyspace. If yes, Try creating your column family from cassandra-cli and see if it works for you.
Also i would suggest to use ThriftClient in place of PelopsClient in your persistence.xml. You can define it as:
<property name="kundera.client.lookup.class"
value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
-Vivek
That worked, thank you.
I'm getting this same issue...
the entity
@Entity
@Table(name = "Cat", schema = "testing@cassandra_pu")
public class Cat {
@Id
@Column(name = "id")
private String id;
@Column(name="tail")
private String tail;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTail() {
return tail;
}
public void setTail(String tail) {
this.tail = tail;
}
public Cat(){
}
}
the test
@Test
public void WriteTest(){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu");
EntityManager em = emf.createEntityManager();
//Persistence.getPersistenceUtil().
Cat cat = new Cat();
cat.setId("1");
cat.setTail("long");
em.persist(cat);
em.close();
emf.close();
}
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="cassandra_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="node2.dc1,node4.dc1,node8.dc1,node3.dc2,node9.dc2,node27.dc2"/>
<property name="kundera.port" value="9160"/>
<property name="kundera.keyspace" value="testing"/>
<property name="kundera.dialect" value="cassandra"/>
<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
<property name="kundera.cache.config.resource" value="/ehcache-test.xml"/>
</properties>
</persistence-unit>
</persistence>
Pom.xml
<dependency>
<groupId>com.impetus.client</groupId>
<artifactId>kundera-cassandra</artifactId>
<version>2.3</version>
</dependency>
From Cassandra:
cqlsh:testing> describe keyspace testing;
CREATE KEYSPACE testing WITH replication = {
'class': 'NetworkTopologyStrategy',
'dc1': '3',
'dc2': '3'
};
USE testing;
CREATE TABLE "Cat" (
id text PRIMARY KEY,
tail text
) WITH
bloom_filter_fp_chance=0.010000 AND
caching='KEYS_ONLY' AND
comment='' AND
dclocal_read_repair_chance=0.000000 AND
gc_grace_seconds=864000 AND
read_repair_chance=0.100000 AND
replicate_on_write='true' AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'SnappyCompressor'};
Running the test results in:
2013-02-13 15:42:22,673 [ERROR] [main] com.impetus.client.cassandra.thrift.ThriftClient - Error while persisting record. Details:
InvalidRequestException(why:Not enough bytes to read value of component 0)
at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:19479)
at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:1035)
at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:1009)
at com.impetus.client.cassandra.thrift.ThriftClient.onPersist(ThriftClient.java:157)
at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:83)
at com.impetus.client.cassandra.thrift.ThriftClient.persist(ThriftClient.java:130)
at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:193)
at com.impetus.kundera.graph.Node.flush(Node.java:525)
at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:422)
at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:167)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:214)
at kundera.KunderaTest.WriteTest(KunderaTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
com.impetus.kundera.KunderaException: com.impetus.kundera.KunderaException: InvalidRequestException(why:Not enough bytes to read value of component 0)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:220)
at kundera.KunderaTest.WriteTest(KunderaTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.impetus.kundera.KunderaException: InvalidRequestException(why:Not enough bytes to read value of component 0)
at com.impetus.client.cassandra.thrift.ThriftClient.onPersist(ThriftClient.java:165)
at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:83)
at com.impetus.client.cassandra.thrift.ThriftClient.persist(ThriftClient.java:130)
at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:193)
at com.impetus.kundera.graph.Node.flush(Node.java:525)
at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:422)
at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:167)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:214)
... 28 more
Caused by: InvalidRequestException(why:Not enough bytes to read value of component 0)
at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:19479)
at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:1035)
at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:1009)
at com.impetus.client.cassandra.thrift.ThriftClient.onPersist(ThriftClient.java:157)
... 35 more
Process finished with exit code 255
To future generations:
You must literally create the column family in cassandra-cli, there is no getting around this.
This generates a table with columns column1 value
which, when inserting per my example creates data like so:
key | column1 | value
-----+---------+-------
1 | tail | long
What happens when you add another property?
key | column1 | value
-----+---------+-------
1 | feet | tiny
1 | tail | long
Okay, that's bizarre. Clearly we need to configure more in the cli:
create column family cat with key_validation_class='UTF8Type' and default_validation_class='UTF8Type' and comparator='UTF8Type' and column_metadata = [ {column_name:feet, validation_class:UTF8Type},{column_name:tail, validation_class:UTF8Type}];
Now when we run the test, we get:
select * from cat;
key | feet | tail
-----+------+------
1 | tiny | long
Enjoy.
I'm still seeing this error in Kundera 2.5. I was hoping the "works with CQL3" thing might have let me use CQL3 to define my table. It seems Kundera 2.5 can only see tables created with CQL2.
I did switch to the Thrift Client Factory. Still got this error :(.
Did you enable cql3 with client? For example as:
Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
PelopsClient pc = (PelopsClient) clientMap.get("cassandra");
pc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
-Vivek
Please refer: https://github.com/impetus-opensource/Kundera/tree/trunk/kundera-cassandra/src/test/java/com/impetus/client/cassandra/thrift/cql
for more junits.
-Vivek
Thank you Vivek! Your first comment didn't do anything, but from those test cases I figured it out. To future generations, to get rid of this you need to create your EntityManager like so:
Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT, propertyMap);
EntityManager entityManager = emf.createEntityManager();
Aah i think missed the point at my end. Just to clarify, Reason first setting will not work is because schema generation happens before entity manager creation! That is required in case you want to explicitly set it for cql3 for JPA CRUD operations and JPQL.
-Vivek
Will get it incorporated as part of wikii.
-Vivek