hibernate HQL选择与删除,为什么交叉连接删除不起作用?

vlf7wbxs  于 2023-01-21  发布在  其他
关注(0)|答案(1)|浏览(141)

为什么这是工作:

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

但这会导致SQL语法错误:

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

错误消息为: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

lyfkaqu1

lyfkaqu11#

HQL和SQL通常(至少据我所知)都不支持delete语句中的连接,但是,您可以使用子查询模拟它,如下所示:

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

相关问题