hibernate restricts.in with and,怎么用?

新手上路,请多包涵

我有如下表

id, employee_no, survey_no, name
1    test          1         test_name
2    test2         1         test_name2
3    test3         1         test_name3
4    test4         2         test_name4

如何通过将下面的 AND 组合成一个 IN 语句来使用 Restriction.in 进行查询?

  IN[   (if(survey_no==1)  && employee_no== 'test')  ,
       (if(survey_no==1)  && employee_no== 'test2') ,
        ...
   ]

原文由 cometta 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 353
1 个回答

我认为这是您要使用的标准组合(顺便说一句。帮助 Hibernate 实体 bean 定义而不是表结构更容易):

 String[] employeeNames = { "test", "test2" };
List<Survey> surveys = getSession().createCriteria(Survey.class).add(
        Restrictions.and
        (
            Restrictions.eq("surveyNumber", 1),
            Restrictions.in("employeeName", employeeNames)
        )
    ).list();

原文由 Daff 发布,翻译遵循 CC BY-SA 2.5 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题