hibernate restrictions.in与和,如何使用? [英] hibernate restrictions.in with and, how to use?

查看:125
本文介绍了hibernate restrictions.in与和,如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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}; 
列表< Survey>调查问卷= getSession()。createCriteria(Survey.class).add(
Restrictions.and

Restrictions.eq(surveyNumber,1),
Restrictions.in employeeName,employeeNames)

).list();


I have table like 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 one IN statement?

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

解决方案

I think this is the criteria combination you want to use (btw. it is easier to help with the Hibernate entity bean definition 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();

这篇关于hibernate restrictions.in与和,如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆