使用 jooq 时出现未知列 sql 错误
Unknown column sql error while using jooq
查询:
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,数据库名称:'users',JOOQ 版本:3.16.6
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/issues/12045
解决方案是:
- 升级您的 MySQL 版本
- 改为使用基于
MULTISET_AGG
的方法
查询:
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,数据库名称:'users',JOOQ 版本:3.16.6
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/issues/12045
解决方案是:
- 升级您的 MySQL 版本
- 改为使用基于
MULTISET_AGG
的方法