babyfish-ct / jimmer

A revolutionary ORM framework for both java and kotlin.
Apache License 2.0
876 stars 88 forks source link

[Bug] deleteById(id) 生成的 SQL 在 MySQL 8 下执行报错 #791

Closed dejavuhuh closed 1 day ago

dejavuhuh commented 6 days ago

问题描述

我有一个树形的菜单表(menu),我调用 deleteById 方法去删除某个菜单的时候,Jimmer 生成了下面这个 SQL eaa715487038619295fc8cdd39a99e50 SQL:delete from menu tb1 where exists(select * from menu tb2 where tb1.PARENT_ID = tb2.ID and tb2.PARENT_ID = ?) 这个 SQL 在 MySQL 8 版本下执行会报错,报错原因是:You can't specify target table 'tb1' for update in FROM clause 436ef1adf873f85087779ad977b1660c 实体定义如下: image

SWQXDBA commented 5 days ago

应该是因为 Mysql不允许修改子查询中出现的表。。。坑爹 这里exists中select了要delete表导致的 https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause

babyfish-ct commented 1 day ago

Try 0.9.20