【问题标题】:Hibernate HQL can't recognize table alias in sub select , Insert Into ... Select ... where column = (Select...)Hibernate HQL 无法识别 sub select 中的表别名,Insert Into ... Select ... where column = (Select...)
【发布时间】:2021-02-13 01:02:01
【问题描述】:

我有这个 HQL,你会注意到它包含同一张表 TABLE_2 的两个实例(tab2 和 tab5):

INSERT INTO TABLE_1 (column, column, column,
column, column, column, column, column)
SELECT column, column, column,
column, column, column, column, column
FROM TABLE_2 as tab2 INNER JOIN tab2.message as tab3 INNER JOIN tab3.service as tab4, TABLE_2 as tab5
WHERE tab2.dateChgt = (SELECT MAX(dateChgt) FROM TABLE_2 WHERE code = :pCd1 AND message.num = tab3.num GROUP BY message.num)
AND tab5.dateChgt = (SELECT MAX(dateChgt) FROM TABLE_2 WHERE code = :pCd2 AND message.num = tab3.num GROUP BY message.num)
AND tab2.code = :pcode1
AND tab5.code = :pcode2
AND tab2.message.num = tab5.message.num
AND tab2.dateChgt <= tab5.dateChgt
AND tab5.dateChgt >= :pDateDebRech
AND tab5.dateChgt <= :pDateFinRech
AND tab3.typeMessage = :pTypeMessage
GROUP BY tab3.num, tab4.column, tab4.column, tab3.column;

所以错误是:“t_message”表的 FROM 子句中的条目引用无效。 提示:也许你想引用表“tmessage1_”的别名。

问题是我已将别名 tab3 赋予 t_message(HQL 中的 tab2.message),但当我调用 tab3.num 时,HQL 不会识别子 Select 中的别名 tab3。

令人惊讶的是,当我删除 Insert into 语句并将查询转移到简单的 Select 查询时,问题就消失了。我也尝试在 PgAdmin(数据库是 PostgreSql)上运行查询,它可以工作,所以我想问题来自 HQL。

有什么想法吗?

谢谢大家

【问题讨论】:

    标签: hibernate select insert subquery hql


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多