使用JOOQ时未知列SQL错误

发布于 2025-01-25 09:03:19 字数 1405 浏览 4 评论 0原文

查询:

this.dslContext.select(
            ROLE.asterisk(),
            multiset(
                select(PERMISSION.asterisk())
                    .from(ROLE_PERMISSION)
                    .innerJoin(PERMISSION)
                    .on(ROLE_PERMISSION.PERMISSION_ID.eq(PERMISSION.ID))
                    .where(ROLE_PERMISSION.ROLE_ID.eq(ROLE.ID))
            ).as("permissions")
        ).from(ROLE)
            .where(ROLE.ID.eq(id))
            .fetchOneInto(Role.class)

错误:

jOOQ; bad SQL grammar [set @t = @@group_concat_max_len; set @@group_concat_max_len = 4294967295; select `users`.`role`.*, (select coalesce(json_merge_preserve('[]', concat('[', group_concat(json_array(`v0`, `v1`) separator ','), ']')), json_array()) from (select `users`.`permission`.`id` as `v0`, `users`.`permission`.`name` as `v1` from `users`.`role_permission` join `users`.`permission` on `users`.`role_permission`.`permission_id` = `users`.`permission`.`id` where `users`.`role_permission`.`role_id` = `users`.`role`.`id`) as `t`) as `permissions` from `users`.`role` where `users`.`role`.`id` = ?; set @@group_concat_max_len = @t;]; nested exception is java.sql.SQLSyntaxErrorException: Unknown column 'users.role.id' in 'where clause'.

数据库:MySQL,数据库名称:'用户',JOOQ版本:3.16.6

Query:

this.dslContext.select(
            ROLE.asterisk(),
            multiset(
                select(PERMISSION.asterisk())
                    .from(ROLE_PERMISSION)
                    .innerJoin(PERMISSION)
                    .on(ROLE_PERMISSION.PERMISSION_ID.eq(PERMISSION.ID))
                    .where(ROLE_PERMISSION.ROLE_ID.eq(ROLE.ID))
            ).as("permissions")
        ).from(ROLE)
            .where(ROLE.ID.eq(id))
            .fetchOneInto(Role.class)

Error:

jOOQ; bad SQL grammar [set @t = @@group_concat_max_len; set @@group_concat_max_len = 4294967295; select `users`.`role`.*, (select coalesce(json_merge_preserve('[]', concat('[', group_concat(json_array(`v0`, `v1`) separator ','), ']')), json_array()) from (select `users`.`permission`.`id` as `v0`, `users`.`permission`.`name` as `v1` from `users`.`role_permission` join `users`.`permission` on `users`.`role_permission`.`permission_id` = `users`.`permission`.`id` where `users`.`role_permission`.`role_id` = `users`.`role`.`id`) as `t`) as `permissions` from `users`.`role` where `users`.`role`.`id` = ?; set @@group_concat_max_len = @t;]; nested exception is java.sql.SQLSyntaxErrorException: Unknown column 'users.role.id' in 'where clause'.

Database: MYSQL, Database Name: 'users', JOOQ Version: 3.16.6

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城烟雨 2025-02-01 09:03:19

MySQL 5.7中不支持相关的派生表。支持仅在MySQL 8.0.14中添加:
https://dev.mysql.com/doc/refman/ 8.0/en/derived-tables.html

JOOQ当前无法处理此限制,请参阅:
https://github.com/jooq/jooq/jooq/sissues/issues/12045

解决方案是解决方案要么:

Correlating derived tables isn't supported in MySQL 5.7. Support has been added only in MySQL 8.0.14:
https://dev.mysql.com/doc/refman/8.0/en/derived-tables.html

jOOQ currently can't work around this limitation, see:
https://github.com/jOOQ/jOOQ/issues/12045

The solution is either:

  • Upgrade your MySQL version
  • Use a MULTISET_AGG based approach instead
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文