gpt4 book ai didi

mysql - 不带 on 子句的 DetachedCriteria

转载 作者:行者123 更新时间:2023-11-30 01:22:18 25 4
gpt4 key购买 nike

我对 Hibernate 比较陌生。我必须使用 3.2 版本,并且需要使用 DetachedCriteria 并获取以下查询:

select this_.ID as ID0_1_, this_.SNDG as SNDG0_1_
, this_.NDG as NDG0_1_, this_.T_GWR_PARTNER_ID as T4_0_1_
, table2x1_.ID as ID1_0_, table2x1_.T_GWR_PROPOSAL_ID as T2_1_0_
, table2x1_.GROUP_SNDG as GROUP3_1_0_, table2x1_.GROUP_NAME as GROUP4_1_0_
from t_gwr_proposals this_
inner join
t_gwr_proposal_ratings table2x1_
where table2x1_.T_GWR_PROPOSAL_ID=this_.ID

但我得到以下内容

select this_.ID as ID0_1_, this_.SNDG as SNDG0_1_
, this_.NDG as NDG0_1_, this_.T_GWR_PARTNER_ID as T4_0_1_
, table2x1_.ID as ID1_0_, table2x1_.T_GWR_PROPOSAL_ID as T2_1_0_
, table2x1_.GROUP_SNDG as GROUP3_1_0_, table2x1_.GROUP_NAME as GROUP4_1_0_
from t_gwr_proposals this_
inner join t_gwr_proposal_ratings table2x1_
** on this_.ID=table2x1_.ID **
where table2x1_.T_GWR_PROPOSAL_ID=this_.ID

使用此代码:

Criteria c = session.createCriteria(T_gwr_proposals.class, "Table1");
c.createAlias("Table1.T_gwr_proposal_ratings", "Table2"); // inner join by default
c.add(Restrictions.eqProperty("Table2.t_gwr_proposal_id", "Table1.proposalsId"));
return c.list();

谁能帮帮我吗?

非常感谢,

托马索A.

最佳答案

标准不适用于表,但适用于实体及其关联。您只能通过两个实体之间存在的关联来连接两个实体。并且条件查询中只能存在一个根实体。因此,除非使用 table2x1_.T_GWR_PROPOSAL_ID=this_.ID 作为映射的实体之间存在关联,否则您将无法在 Criteria 中创建此类查询(不过,HQL 应该没问题)。

关于mysql - 不带 on 子句的 DetachedCriteria,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18404566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com