2 Replies Latest reply on Jun 24, 2009 7:44 AM by rizqureshi2

    multiple or with hibernate criteria

    rizqureshi2

      Anyone has come across the problem where you need to define multiple or statement in a hibernate criteria. Consider the following code segment:

      Criteria crit = session.createCriteria(Project.class);
       Criteria jobs = crit.createCriteria("jobTypes");
      jobs.add(Restrictions.or(Restrictions.eq("id", 1),
       Restrictions.or(Restrictions.eq("id", 2),
       Restrictions.or(Restrictions.eq("id", 3),
       Restrictions.or(Restrictions.eq("id", 4),Restrictions.eq("id", 5))
       ))));
      

      Now, how would one create such a nested OR cirterion using for/while loop if one has any number of different ids {1,2,3,4,5,6.....}?

      Thanks,
      Rizwan