Hibernate Create Criteria两次连接同一张表-尝试了2种方法,但有2个差异错误

Hibernate Create Criteria两次连接同一张表-尝试了2种方法,但有2个差异错误,第1张

Hibernate Create Criteria两次连接同一张表-尝试了2种方法,但有2个差异错误

关于2005年打开的问题,还有一个旧的Hibernate错误HHH-879

org.hibernate.QueryException:duplicate association path
仍在打开…

其他问题已关闭,但没有解决方案HHH-7882

因此,选项1)不太适合。

但是,在上述错误的意见的有用 的解决方法 是使用提及

exists

因此,请使用两次

sqlRestriction
exists
并使用一个相关的子查询来过滤属性类别。您将获得唯一的 企业 连接到这两个类别。

crit.add( Restrictions.sqlRestriction(   "exists (select null from Company_Customercategory a where {alias}.company_Id = a.company_Id and a.CUSTOMERCATEGORYID = ?)",  1, IntegerType.INSTANCE ) );crit.add( Restrictions.sqlRestriction(   "exists (select null from Company_Customercategory a where {alias}.company_Id = a.company_Id and a.CUSTOMERCATEGORYID = ?)",  6, IntegerType.INSTANCE ) );

这导致以下查询提供正确的结果

select this_.COMPANY_ID as COMPANY_ID1_2_0_, this_.COMPANY_NAME as COMPANY_NAME2_2_0_ from COMPANIES this_ where exists (select null from Company_Customercategory a    where this_.company_Id = a.company_Id and a.CUSTOMERCATEGORYID =  ?) and       exists (select null from Company_Customercategory a    where this_.company_Id = a.company_Id and a.CUSTOMERCATEGORYID = ?)


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5462732.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存