【问题标题】:Deleting all Entities of a certain type删除特定类型的所有实体
【发布时间】:2015-04-29 15:13:31
【问题描述】:

我正在尝试从我的 GAE 应用程序的数据存储中删除某种类型的所有实体。我有以下行:

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

我看到以下异常:

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

我假设我没有正确使用别名,因为它会将 DELETE 误认为是实际类。我试着在没有别名的情况下只做DELETE FROM MyClassType,但这似乎不起作用。

有什么想法吗?

【问题讨论】:

    标签: java google-app-engine jpql


    【解决方案1】:

    如果您想删除所有实体,则不需要此处所述的变量 [1]。

    另外,您使用的是getSimpleName() 方法,我对JPA 知之甚少,但我见过的所有sn-ps 代码都使用getName() 方法。请参阅此处的差异 [2]。因此,查询将是:

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

    [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?

    【讨论】:

      猜你喜欢
      • 2017-08-09
      • 2020-12-06
      • 1970-01-01
      • 1970-01-01
      • 2013-10-28
      • 1970-01-01
      • 2021-09-18
      • 2011-08-30
      • 1970-01-01
      相关资源
      最近更新 更多