我試圖執行刪除查詢在Eclipse的HQL工具休眠 - 刪除日食休眠工具HQL
delete from Address address where address.id = 6
以下,但我得到了
org.hibernate.hql.QueryExecutionRequestException: Not supported for DML operations
請告訴我,我已經做了錯誤。 謝謝。
我試圖執行刪除查詢在Eclipse的HQL工具休眠 - 刪除日食休眠工具HQL
delete from Address address where address.id = 6
以下,但我得到了
org.hibernate.hql.QueryExecutionRequestException: Not supported for DML operations
請告訴我,我已經做了錯誤。 謝謝。
This post建議嘗試手動打開會話,然後運行刪除。
我有同樣的問題。你的問題不是使用DML ......第一個建議發佈了DML解決方案的鏈接,但你的問題是針對SQL。
這適用於SQL。
String sql = "delete from ServiceProviderMapping where id=7";
Query query = hibernateSession.createQuery(sql);
query.executeUpdate();
請嘗試以下方法:
final String hql = "delete from Job where jobId = :id";
Query query = session.createQuery(hql).setLong("id", jobId);
query.executeUpdate();
嘗試對更新方法的註釋@Modifying
。
根據[Spring文檔](https://docs.spring.io/spring-data/jpa/docs/current/reference/html/# jpa.modifying-queries),無論何時添加自定義行爲以修改僅需要參數綁定的查詢,都可以使用@ @Menifying註解 – Narasimha 2017-01-30 17:12:44
複製/粘貼不是一個好的答案......請解釋 – Andrew 2012-11-04 07:48:23