I have list of category. I need a list of category by excluding 2,3 row. Can we achieve through hibernate by using Criteria and Restriction?
Hope it helps. I got it to work with this : \n criteria. add(Expression. not(Expression.in("paraType", new String[]{"0", "4", "5", "6", "7", "a", "b", "c"}))); \n I will try your solution too !!
The Criteria interface makes it easy to selectively fetch the data on the basis of conditions in the select query. The Restriction class in hibernate provide several methods that can be used as conditions (also known as Criterion). These conditions are added to a criteria object with the add() method.
Restrictions with CriteriaCriteria cr = session. createCriteria(Employee. class); Criterion salary = Restrictions.gt("salary", 2000); Criterion name = Restrictions. ilike("firstNname","zara%"); // To get records matching with OR conditions LogicalExpression orExp = Restrictions.or(salary, name); cr.
Your question is somewhat unclear. Assuming "Category" is a root entity and "2,3" are ids (or values of some property of the category") you can exclude them using the following:
Criteria criteria = ...; // obtain criteria from somewhere, like session.createCriteria() criteria.add( Restrictions.not( // replace "id" below with property name, depending on what you're filtering against Restrictions.in("id", new long[] {2, 3}) ) );
Same can be done with DetachedCriteria
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With