java - Blaze Persistence Join 子查询问题
问题描述
我正在尝试通过使用 blaze 位持久性来连接子查询,我有一个标准构建器,如下所示,
cbf.create(em, b.class, "foo")
.innerJoinOnSubquery(aCTE.class, "maxEnt")
.from(a.class, "subFoo")
.bind("account_id").select("subFoo.accountId","account_id")
.bind("id").select("subFoo.id","id")
.where("subFoo.accountId").eq(100L)
.end()
.on("maxEnt.account_id").eqExpression("foo.accountId")
.end()
.where("foo.accountId").eq(100L);
当我执行它时,我得到如下的 sql 查询
SELECT s0_.id FROM b s0_
INNER JOIN (SELECT t0_.account_id AS col_0_0_,
t0_.id AS col_1_0_
FROM a t0_
WHERE t0_.account_id = 100 ) t1_
ON ( ( NULL IS NULL )
AND s0_.account_id = t1_.account_id) WHERE s0_.account_id = 100
问题出现在on 子句中,当我尝试比较 on 子句中的两个表 account_id 时,我收到列缺失错误,因为默认情况下在子查询中为 account_id 形成别名。请让我知道如何解决它。我正在使用 hibernate5.4 JPA 供应商。
问题:DB::Exception:表 't1_' 中没有列 't1_.account_id':处理 t1_.account_id 时。
解决方案
这可能是一个错误。为此,我打开了https://github.com/Blazebit/blaze-persistence/issues/1285 。您能否告诉我您正在使用哪个 Hibernate 版本,如果您在 WHERE 子句之前添加右括号,SQL 查询是否有效?这里似乎缺少括号,但我还不知道为什么。
更新:
试试这个作为一种解决方法:
cbf.create(em, b.class, "foo")
.with(aCTE.class) // Maybe pass false as second argument to avoid inlining
.from(a.class, "subFoo")
.bind("account_id").select("subFoo.accountId","account_id")
.bind("id").select("subFoo.id","id")
.where("subFoo.accountId").eq(100L)
.end()
.innerJoinOn(aCTE.class, "maxEnt")
.on("maxEnt.account_id").eqExpression("foo.accountId")
.end()
.where("foo.accountId").eq(100L);
推荐阅读
- security - 最好的办法 ?在 recaptcha 站点密钥或 API 密钥或两者中添加域
- javascript - 如何使用jQuery根据点击表列表更改选择下拉值?
- laravel - 如何使用紧凑的laravel重定向回来
- python - 限制 hydra 结构化配置中的可能值
- multithreading - 指向在函数中创建的局部变量的指针
- string - 解决 LeetCode #13 罗马到整数问题(字符比较)
- sql-server - 消息 156,级别 15,状态 1,第 115 行关键字“选择”附近的语法不正确
- angular - Angular 11 模板解析错误:不是已知元素
- structure - DBT - 为最终业务模型创建暂存视图的最佳实践
- sequelize.js - 无法将我本地系统中的 Sequelize 连接到 cloudSQ。我收到此错误: