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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top