robinmag
robinmag

Reputation: 18120

hibernate - delete hql in eclipse hibernate tool

I tried to execute a delete query as following in eclipse's HQL tool

delete from Address address where address.id = 6

but i got the

org.hibernate.hql.QueryExecutionRequestException: Not supported for DML operations

Please tell me that i've done wrong. Thank you.

Upvotes: 12

Views: 13737

Answers (4)

khoi nguyen
khoi nguyen

Reputation: 409

Try the annotation @Modifying on the update method.

Upvotes: 24

Mr. Green
Mr. Green

Reputation: 11

Please try the following:

final String hql = "delete from Job where jobId = :id";
Query query = session.createQuery(hql).setLong("id", jobId);

query.executeUpdate();

Upvotes: 1

Matt Calderaro
Matt Calderaro

Reputation: 31

I had same issue. Your issue is not for using DML... the first suggestion posted a link for a solution for DML, but your question is for SQL.

This works below for SQL.

String sql = "delete from ServiceProviderMapping where id=7";
Query query = hibernateSession.createQuery(sql);
query.executeUpdate();

Upvotes: 3

Kaleb Brasee
Kaleb Brasee

Reputation: 51965

This post suggests trying to open a session manually, and then run the delete.

Upvotes: 0

Related Questions