Hibernate Criteria,连接不生成正确的SQL

时间:2014-07-23 18:33:05

标签: java sql hibernate sybase-ase

我试图执行Criteria查询但是当我执行代码时,SQL只会在from子句中调出company_synonym而不是其他两个。

映射是:

  • 公司有1对多公司同义词

  • 公司有1对多的CompanyProductRoles

我希望查询返回CompanySynonym对象,所以我尝试了这个:

Criteria criteria = session.createCriteria(CompanySynonym.class, "cs")
    .createAlias("cs." + CompanySynonym.COMPANY, "cmp")
    .createAlias("cmp." + Company.COMPANY_PRODUCT_ROLE, "cpr")
    .add(Restrictions.eq("cs." + CompanySynonym.TYPE, "1234"))
    .add(Restrictions.eq("cpr." + CompanyProductRole.PRODUCT_ID, Integer.valueOf(productId)))
    .add(Restrictions.isNotNull("cpr." + CompanySynonym.Company_ID))
    .add(Restrictions.eq("cpr." + CompanyProductRole.ROLE_CODE, "AB"));

它会生成这个SQL:

select this_.company_syn_id_i as company1_0_0_, this_.company_id_i as company5_0_0_, this_.cmp_syn_end_d as cmp2_0_0_, this_.cmp_syn_type_cd_c as cmp3_0_0_, this_.cmp_syn_c as cmp4_0_0_ 
from product.dbo.company_synonym this_ 
where this_.cmp_syn_type_cd_c=? 
and cpr1_.product_id_i=? 
and cpr1_.company_id_i is not null 
and cpr1_.role_cd_c=c

我在这里错过了什么或做错了什么?

0 个答案:

没有答案