gpt4 book ai didi

hibernate 条件 api 'Select in'

转载 作者:行者123 更新时间:2023-12-04 10:31:19 24 4
gpt4 key购买 nike

是否可以使用 hibernate critiria api 创建“select in”查询?

例子 :
我在 1:n 关系中有两个表,公司和部门

select * from company c where c.id in (select company_id from department d 
where d.departmentname = 'HR' and d.location = 'xyz')

最佳答案

您可以使用此 DetachedCriteria

DetachedCriteria subCriteria= DetachedCriteria.forClass(Departament.class);
subCriteria.add(Property.forName("departmentname ").eq("HR"));
subCriteria.add(Property.forName("location ").eq("xyz"));
subCriteria.setProjection(Projections.property("company_id "));

DetachedCriteria criteria = DetachedCriteria.forClass(Company.class);
criteria.add(Property.forName("id").in(subCriteria));

关于 hibernate 条件 api 'Select in',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4097161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com