栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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 = ?)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/670164.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号