问题
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