简体   繁体   English

删除特定类型的所有实体

[英]Deleting all Entities of a certain type

I am trying to delete all entities of a certain type from the datastore within my GAE application. 我正在尝试从GAE应用程序内的数据存储中删除特定类型的所有实体。 I have the following line: 我有以下几行:

em.createQuery("DELETE m FROM "+UpdateMessage.class.getSimpleName()+" m").executeUpdate();  

I am seeing the following exception: 我看到以下异常:

 Unable to update most recent message in datatstore: Candidate class could not be found: DELETE 

I'm assuming that I am not doing the aliasing right, as it is mistaking the DELETE for an actual class. 我假设我没有正确使用别名,因为它误将DELETE用作实际类。 I tried just doing DELETE FROM MyClassType without the alias, but that didn't seem to work. 我尝试仅在不使用别名的情况下DELETE FROM MyClassType进行DELETE FROM MyClassType ,但这似乎不起作用。

Any ideas? 有任何想法吗?

If you want to remove all entities you won't need a variable as explained here [1]. 如果要删除所有实体,则不需要此处说明的变量[1]。

Also, you are using the method getSimpleName(), I know little about JPA but all of the code snippets I've seen use the getName() method instead. 另外,您使用的是getSimpleName()方法,我对JPA知之甚少,但是我看到的所有代码段都使用getName()方法代替。 See differences here [2]. 在这里看到差异[2]。 Therefore, the query would be: 因此,查询将是:

em.createQuery("DELETE FROM " + UpdateMessage.class.getName()).executeUpdate();  

[1] http://www.objectdb.com/java/jpa/query/jpql/delete [1] http://www.objectdb.com/java/jpa/query/jpql/delete

[2] What is the difference between canonical name, simple name and class name in Java Class? [2] Java类中的规范名称,简单名称和类名称有什么区别?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM