java - hibernate restrictions.in with and,怎么用?

标签 java sql hibernate

我有如下表格

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') ,
        ...
   ]

最佳答案

我认为这是您要使用的条件组合(顺便说一句。帮助 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();

关于java - hibernate restrictions.in with and,怎么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2719642/

相关文章:

java - 通过 jSTL 检查复选框

java - 为什么 JPA 对于 @ManyToOne 关系默认使用 FetchType EAGER

java - 无法执行存储过程JPA

java - 如何在开关盒中使用枚举

java - Selenium : Handling Loading screens obscuring the web elements.(Java)

java - 从其他类读取线程字段

mysql - 如何在 SQL 内连接中添加别名?

sql - Postgresql:检查列是否同时等于多个值的最佳方法

SQL Server 服务卡在 ‘Starting’ 状态

java - SequenceGenerators 名称在 Hibernate 5 中全局唯一吗?