Kundera for Cassandra - Deleting record by row key
题
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?
解决方案
What you can do as a workaround is:
Find using: User u = em.find(User.class, userId)
and then, em.delete(u);
其他提示
Also, http://groups.google.com/group/kundera-discuss/subscribe can give you quick and better support to discuss issues around Kundera.
-Vivek
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();
不隶属于 StackOverflow