How TO Use OR Condition (in Criteria Query) In Hibernate?

Hibernate_Logo

Suppose you want to fetch a mobile list from mobileList table where mobile status is either 1 or 5 (in status column of mobileList  table). We can fetch easily using Criteria Query and Restrictions API of Hibernate using OR Condition.

Here is the code:
  final Integer status=1;
final Integer statusSec = 5;
final Session session=this.getSession();
final Criteria criteria=session.createCriteria(MobileList.class);
criteria.add(Restrictions.or(Restrictions.eq("status",status),
Restrictions.eq("status",statusSec)));

Reference:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment