Kundera for Cassandra - Deleting record by row key

大兔子大兔子 提交于 2019-12-13 17:22:13

问题


I'm trying to delete specific record from database by row key. But when I try to execute this query:

 Query query = em.createQuery(
            "DELETE FROM User u WHERE u.userId = :u");

 query.setParameter("u", userID).executeUpdate();

I got this exception: "Condition = is not suported for query on row key!".

Is there any workaround, or I missing something?


回答1:


What you can do as a workaround is:

Find using: User u = em.find(User.class, userId)

and then, em.delete(u);




回答2:


Also, http://groups.google.com/group/kundera-discuss/subscribe can give you quick and better support to discuss issues around Kundera.

-Vivek




回答3:


A possible approach to perform such a delete (in one command using Kundera, version 2.2 at the moment) is to use "native query", for example:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu");

EntityManager em = emf.createEntityManager();

// "table" is the table name (case sensitive) you name your table in Cassandra
String query = "delete from table where key = 'keyValue'";

// "TablePersistencyEntity" is the Kundera Persistency Entity (Class) for the "table" 
Query q = em.createNativeQuery(query, TablePersistencyEntity.class);
q.getResultList();

em.close();


来源:https://stackoverflow.com/questions/11522120/kundera-for-cassandra-deleting-record-by-row-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!