我对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();有人能帮帮我吗?
非常感谢,
Tommaso A.
发布于 2013-08-23 23:22:31
条件不适用于表,但适用于实体及其关联。您只能通过两个实体之间存在的关联来联接这两个实体。并且一个条件查询中只能存在一个根实体。因此,除非使用table2x1_.T_GWR_PROPOSAL_ID=this_.ID作为映射的实体之间存在关联,否则无法在Criteria中创建这样的查询(不过,HQL应该可以做得很好)。
https://stackoverflow.com/questions/18404566
复制相似问题