Construct Hibernate Criteria Query with OR clause
public List<Employee> getEmployees(final Set<String> employeeCodes)
{
List<Employee> employees = (List<Employee>) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(final Session session) throws HibernateException, SQLException
{
{
final Criteria criteria = session.createCriteria(Employee.class);
if(employeeCodes.size() > 1000){
final Set<String> codes = new HashSet<String>();
Disjunction disjuntion = Restrictions.disjunction();
for(Iterator<String> iterator = employeeCodes.iterator(); iterator.hasNext();){
if(codes.size() < 1000){
codes.add(iterator.next());
}else{
criteria.add(disjuntion.add(Restrictions.in("employeeCode",codes)));
codes.clear();
}
}
}else{
criteria.add(Restrictions.in("employeeCode",employeeCodes));
}
return criteria.list();
}
}
});
return employees;
}
Written by Rajesh
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#