Rajendra Gupta
Rajendra Gupta

Reputation: 379

Hibernate Criteria OR Restriction - fetch list if either one or both columns value is 1

My Table structure is as follows:

enter image description here

Can someone help with the following criteria query:

Criteria c = getSession().createCriteria(getEntity(), "b");
c.add(Restrictions.in("b.isTwitterVerified", 1));
or // b.isFbVerified =1// something like this
return c.list();

Upvotes: 1

Views: 2221

Answers (1)

Maciej Kowalski
Maciej Kowalski

Reputation: 26522

This should return what your after:

Criteria criteria = getSession().createCriteria(getEntity(), "b"); 
Criterion isTwitterVerified = Restrictions.eq("b.isTwitterVerified", 1);
Criterion isFbVerified = Restrictions.eq("b.isFbVerified ", 1);
criteria.add(Restrictions.or(isTwitterVerified , isFbVerified ));

return criteria.list();

On the side.. the in restriction that you tried to use: Restrictions.in.. this would have its place when you would like to verify a certain field against many values (1,3,5 for example).

Upvotes: 5

Related Questions