i can not excute native batch CQL !
i try to excute batch cql by using kundera2.2's native Query in cassandra 1.1.5 , it failed. Is kundera2.2 not support btach cql ?
[MY BTACH CQL3]
BEGIN BATCH USING CONSISTENCY QUORUM INSERT INTO users (userid, password, name) VALUES ('user2', 'ch@ngem3b', 'second user'); UPDATE users SET password = 'ps22dhds' WHERE userid = 'user3'; INSERT INTO users (userid, password) VALUES ('user4', 'ch@ngem3c'); DELETE name FROM users WHERE userid = 'user1'; APPLY BATCH;
[MY CODE] Query query = entityManager.createNativeQuery(strCql, clazz); query.executeUpdate();
I did not try it yet. But i guess executing these as seperate cql3 statements should work!
There is another alternative(JPA Way) to execute this.
setConsistencyLevel() => QUORUM
define batch.size in persistence.xml
Perform your INSERT/UPDATE/DELETE via em over Objects. And then invoke em.flush() for explicit flush, else depending upon batch size it will implicitly flush them down.
-Vivek
I need to look into, but i guess cassandra java driver must be wrapping this up into addBatch() and executeBatch() jdbc calls!
-Vivek
I guess, you need to try it without ";" Here it is:
BEGIN BATCH USING CONSISTENCY QUORUM
INSERT INTO users (KEY, password, name) VALUES ('user2', 'ch@ngem3b', 'second user')
UPDATE users SET password = 'ps22dhds' WHERE KEY = 'user2'
INSERT INTO users (KEY, password) VALUES ('user3', 'ch@ngem3c')
DELETE name FROM users WHERE key = 'user2'
INSERT INTO users (KEY, password, name) VALUES ('user4', 'ch@ngem3c', 'Andrew')
APPLY BATCH;
http://www.datastax.com/docs/1.0/references/cql/BATCH
i tried it. the error happend.
[Error Msg]
javax.persistence.PersistenceException: InvalidRequestException(why:line 4:0 no viable alternative at input 'APPLY')
at com.impetus.client.cassandra.CassandraClientBase.executeQuery(CassandraClientBase.java:710)
at com.impetus.client.cassandra.pelops.PelopsClient.executeQuery(PelopsClient.java:597)
at com.impetus.client.cassandra.query.CassQuery.onExecuteUpdate(CassQuery.java:209)
at com.impetus.kundera.query.QueryImpl.executeUpdate(QueryImpl.java:134)
at pokemon.common.base.BaseService.exeNativeUpdate(BaseService.java:287)
at pokemon.common.service.Test1Service.doBatch(Test1Service.java:126)
at pokemon.common.service.Test1Service$$FastClassByCGLIB$$e6f45817.invoke(
Just now a test case is added demonstrate the same, have a look at commit ada7cacf9aa48f27de6c02463bff0689171e7513 for reference.
A new test case " testCQLBatch()" added.
thank you very much! it is working well now!
Great! 1 question:
Using/Analyzing kundera for ?
-Vivek
it's kundera 2.2
Ok . I mean using Kundera for developing any application or creating a case study?
-Vivek
i am using kundera2.2(2.3) + cassandra1.2(cql3/jpql/jdbc) developing a big application. thank you for your support!!!
when there are more than one table to update/delete/insert, how can i do the batch? you know that only one entity "CassandraBatchEntity " can be set in the createNativeQuery().
Query q = em.createNativeQuery(useNativeSql, CassandraBatchEntity.class);
it did not work when update/insert two different tables in the batch !
please share what are you trying to execute? Entity class is required only to map with database and will wrap into that entity in case of select.(q.getresultList()) . Hence it should work on multiple tables.
-Vivek
[MY CQL]
BEGIN BATCH USING CONSISTENCY QUORUM
INSERT INTO test1(id, url) VALUES ('64907b40-29a1-11e2-93fa-90b11c71b811','w')
INSERT INTO test2(key, count) VALUES ('key1',12)
APPLY BATCH;
[MY CODE] ... Query q = em.createNativeQuery(useNativeSql, Test1Entity.class); q.executeUpdate ...
[ERROR MSG] javax.persistence.PersistenceException: InvalidRequestException(why:Unknown identifier key) at com.impetus.client.cassandra.CassandraClientBase.executeQuery(CassandraClientBase.java:710) at com.impetus.client.cassandra.pelops.PelopsClient.executeQuery(PelopsClient.java:597) at com.impetus.client.cassandra.query.CassQuery.onExecuteUpdate(CassQuery.java:209) at com.impetus.kundera.query.QueryImpl.executeUpdate(QueryImpl.java:134)
As per error message:
[ERROR MSG]
javax.persistence.PersistenceException: InvalidRequestException(why:Unknown identifier key)
at com.impetus.client.cassandra.CassandraClientBase.executeQuery(CassandraClientBase.java:710)
at com.impetus.client.cassandra.pelops.PelopsClient.executeQuery(PelopsClient.java:597)
at com.impetus.client.cassandra.query.CassQuery.onExecuteUpdate(CassQuery.java:209)
at com.impetus.kundera.query.QueryImpl.executeUpdate(QueryImpl.java:134)
Looks like column family "test2" does not have a column with name "key" ! It has nothing to do Kundera.
i have confirmed that there is a column in the "test2" table!
"InvalidRequestException(why:Unknown identifier key)" is thrown by Cassandra itself. Which means it is not able to find that identifier.
-Vivek
Are you able to execute:
BEGIN BATCH USING CONSISTENCY QUORUM INSERT INTO test1(id, url) VALUES ('64907b40-29a1-11e2-93fa-90b11c71b811','w') INSERT INTO test2(key, count) VALUES ('key1',12)
APPLY BATCH;
from CQL shell?
-Vivek
yes, it can work well in CQL shell;
Ok. Please share column family creation script with "test1" and "test2"
-Vivek