Hibernate limits.in with and how to use?

I have a table as below

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

How to query with Restriction.in by combining below AND into a single IN statement?

 IN[   (if(survey_no==1)  && employee_no== 'test')  ,  
       (if(survey_no==1)  && employee_no== 'test2') ,
        ...
   ]
+5
source share
1 answer

I think this is a combination of criteria that you want to use (by the way, it is easier to simplify the definition of the hibernate bean entity instead of the table structure):

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

All Articles