Reputation: 1645
I'm trying to run a delete all on a domain class where I qualify one of the classes attribute values (both Member.submissionId and submission.id as long types).
Here's my code:
def memberCount = Member.where{ eq( "submissionId", submission.id ) }.deleteAll()
Here's the exception I get:
nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: member near line 1, column 57 [DELETE my.domain.Member member WHERE (member.submissionId=?)]
Other deletes I have where I reference the submission object seem to work ok:
def subErrorCount = SubmissionError.where{ eq( "submission", submission ) }.deleteAll()
For this delete, the generated SQL is correct:
delete from submission_error where submission_id=?
The only difference I can see is that SubmissionError belongs to the parent Submission object, where Member has a soft link to the Submission via its submissionId attribute (it belongs to another object).
Any suggestions?
EDIT: also, am I correct in assuming that this delete method is not a cascade delete due to the SQL it generates? i.e. objects that belong to the selected Members will not be deleted.
Upvotes: 1
Views: 1518
Reputation: 12334
You can avoid the badly generated HQL by writing the query as an HQL query yourself:
Member.executeUpdate("delete Member m where m.submissionId = :subId", [subId: submission.id])
Upvotes: 1
Reputation: 577
Looks like 'member' is a reserved word in HQL. I would suggest changing the domain model name if it's not much of a hassle.
Upvotes: 1