kundera icon indicating copy to clipboard operation
kundera copied to clipboard

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)

Open Gargee opened this issue 13 years ago • 8 comments

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: com.impetus.kundera.KunderaPersistence

    </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 http://nexus.sb.karmalab.net/nexus/content/repositories/build-test-snapshot expedia-jlux-snapshot sonatype-nexus Kundera Public Repository https://oss.sonatype.org/content/repositories/releases true false kundera-missing Kundera Public Missing Resources Repository http://kundera.googlecode.com/svn/maven2/maven-missing-resources true true and the Following Dependencies com.impetus.client kundera-cassandra 2.5 org.apache.cassandra cassandra-all 1.2.0 Can you please let me know is wrong with this code?

Gargee avatar Jun 07 '13 16:06 Gargee

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

mevivs avatar Jun 07 '13 16:06 mevivs

You can also refer to: https://github.com/impetus-opensource/Kundera/issues/278

for more details on enabling CQL3 version with Kundera.

-Vivek

mevivs avatar Jun 07 '13 16:06 mevivs

Similar to https://github.com/impetus-opensource/Kundera/issues/166

mevivs avatar Jun 07 '13 16:06 mevivs

Tried all the above mentioned steps Vivek,but still getting the same error.

Gargee avatar Jun 07 '13 21:06 Gargee

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

mevivs avatar Jun 07 '13 23:06 mevivs

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));

Gargee avatar Jun 08 '13 02:06 Gargee

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

mevivs avatar Jun 08 '13 04:06 mevivs

Thanks Vivek it works.

Gargee avatar Jun 08 '13 12:06 Gargee