0

我对 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.

4

1 回答 1

0

标准不适用于表,但适用于实体及其关联。您只能通过它们之间存在的关联加入两个实体。并且条件查询中只能存在一个根实体。因此,除非使用 table2x1_.T_GWR_PROPOSAL_ID=this_.ID 作为其映射的实体之间存在关联,否则您将无法在 Criteria 中创建这样的查询(尽管 HQL 应该可以正常工作)。

于 2013-08-23T15:22:31.233 回答