Hibernate criteria api 'Select in'

前端 未结 1 1240
野性不改
野性不改 2021-01-12 09:34

is it possible to create a \'select in\'-query with the hibernate critiria api ?

Example : I have two tables in a 1:n relation, company and department



        
相关标签:
1条回答
  • 2021-01-12 10:04

    You can use for this 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));
    
    0 讨论(0)
提交回复
热议问题