07 Jun 2013 08:48:37,139 ERROR main com.impetus.client.cassandra.thrift.ThriftClient (ThriftClient.java:165) - Error while persisting record, Caused by: InvalidRequestException(why:Not enough bytes to read value of component 0)
I am trying to persist my entity object into Cassandra DB using Kundera API.But I am getting this
com.impetus.client.cassandra.thrift.ThriftClient (ThriftClient.java:165) - Error while persisting record, Caused by: InvalidRequestException(why:Not enough bytes to read value of component 0)
My Code looks like this:-
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;
@Entity @Table(name="mediaCategoryGroup", schema="KunderaExamples@cassandra_pu") public class MediaCategory {
@Id
@Column(name= "MCategoryID")
private int MCategoryID;
@Column(name= "MCategoryName")
private String MCategoryName;
//No Argument Constructor
public MediaCategory() {
}
//Parameterized Constructor public MediaCategory(int mCategoryID, String mCategoryName) {
MCategoryID = mCategoryID;
MCategoryName = mCategoryName;
}
public int getMCategoryID() {
return MCategoryID;
}
public void setMCategoryID(int mCategoryID) {
MCategoryID = mCategoryID;
}
public String getMCategoryName() {
return MCategoryName;
}
public void setMCategoryName(String mCategoryName) {
MCategoryName = mCategoryName;
}
}
The create Statement of this table is
CREATE TABLE mediaCategoryGroup (MCategoryID int, MCategoryName varchar, PRIMARY KEY(MCategoryID));
My Persistence.xml is :-1:
</properties>
</persistence-unit>
I am trying to persist it using the following code in my test class:
public void Create() {
MediaCategory U1 = new MediaCategory (100,"Century");
em.persist(U1);
}
I have included these repositories in my pom.xml
You need to enable CQL3 version before persisting record. You can enable it as:
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();
-Vivek
You can also refer to: https://github.com/impetus-opensource/Kundera/issues/278
for more details on enabling CQL3 version with Kundera.
-Vivek
Similar to https://github.com/impetus-opensource/Kundera/issues/166
Tried all the above mentioned steps Vivek,but still getting the same error.
Please compare your code with basic example at: https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/PersonCassandraTest.java
Else, please share link to download your sample code base.
-Vivek
Hi Vivek, I have uploaded the code here: https://github.com/Gargee/KunderaPoc
Basically when i m creating the column Families using CLI this is working.But it doesnt when i create the column Families using CQL. /*Through CLI if created
- create column family MediaCategoryGroup with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
- Or
- Through CQL if created CREATE TABLE "MediaCategoryGroup" (MCategoryID varchar, MCategoryName varchar, PRIMARY KEY(MCategoryID));
Ok. Will have a look. Prima facie, had a look at:
https://github.com/Gargee/KunderaPoc/blob/master/src/main/java/com/Kundera/poc/CRUD.java
AND https://github.com/Gargee/KunderaPoc/blob/master/src/main/java/com/Kundera/poc/KunderaExample.java
I can see that
https://github.com/Gargee/KunderaPoc/blob/master/src/main/java/com/Kundera/poc/CRUD.java is missing :
Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu", propertyMap);
EntityManager entityManager = emf.createEntityManager();
for
CRUD c = new CRUD();
//creating the data
c.Create();
i believe, it will use emf and em created by CRUD.java, not the one defined in KunderaExample.java
You may want to change in CRUD.java and give it a try.
-Vivek
Thanks Vivek it works.