littleAlien
littleAlien

Reputation: 821

HQL select vs delete. Why delete with cross join doesn't work?

Why this is working:

@Query("from Ban b where b.banned.uuid = :uuid")

but this cause SQL syntax error:

@Query("delete Ban b where b.banned.uuid = :uuid")

Error message is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cross join user user1_ where uuid=x'53......'' at line 1

Upvotes: 0

Views: 336

Answers (1)

Gavin King
Gavin King

Reputation: 4293

Neither HQL nor, usually—at least as far as I know—SQL, supports joins in delete statements. However, you can emulate it with a subquery, something like:

delete Ban b where b.bannedid = (select bb.id from Banned bb where bb.uuid = :uuid)

Upvotes: 1

Related Questions