简体   繁体   中英

Delete Query(named native Query) is not working in JPA with Hibernate specification

I have my named native query in orm.xml as,

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

I'm trying to execute this query in my code as

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

Entity Manager itself not creating when I have query in orm.xml, getting below exception

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

But the same query is working when I use createNativeQuery()

result class is missing here, It's resolved Once I changed to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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