【问题标题】:Delete Query(named native Query) is not working in JPA with Hibernate specification删除查询(命名为原生查询)在 JPA 中与 Hibernate 规范不起作用
【发布时间】:2012-05-02 10:16:39
【问题描述】:

我在 orm.xml 中有我命名的本机查询,

<named-native-query name="deleteAuthTokenByToken">
    <query><![CDATA[DELETE FROM AUTH_TOKEN WHERE TOKEN=:token]]></query>
</named-native-query>

我正在尝试在我的代码中执行此查询

em.getTransaction().begin();
em.createNamedQuery("deleteAuthTokenByToken").setParameter("token", token).executeUpdate();
em.getTransaction().commit();

当我在 orm.xml 中进行查询时,实体管理器本身没有创建,低于异常

Caused by: org.hibernate.cfg.NotYetImplementedException: Pure native scalar queries are not yet supported

但是当我使用 createNativeQuery() 时,相同的查询正在工作

【问题讨论】:

    标签: hibernate jpa


    【解决方案1】:

    这里缺少结果类,一旦我更改为,它就解决了

    <named-native-query name="deleteAuthTokenByTokenAndOrgId" result-class="com.modria.jpa.DO.AuthToken">
        <query><![CDATA[DELETE FROM AUTH_TOKEN WHERE TOKEN=:token AND ORG_ID=:orgId]]></query>
    </named-native-query>
    

    【讨论】:

      猜你喜欢
      • 2017-02-25
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 2017-03-14
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多