Reputation: 1
I am new to Hibernate Restrictions and need some help:
I am having a scenario that I need to find all the records where "identifier" is "HB001" or "HB002", "HB003" &"HB004". That is to say, it should return 4 rows, each row has "identifier" as "HB00*".
//here is the code
Criteria criteria = hibernateSession.createCriteria(ENTITY_CLASS);
List<String> ids = getIds(); //ids contains "HB001", "HB002", "HB003", "HB004" and I am sure this step has no issue.
criteria.add(Restrictions.eq("identifier", ids));
...
looks like the criteria.add(Restrictions.eq("identifier", ids))
is not correct and the query returns null.
Can anyone help?
Upvotes: 0
Views: 3890
Reputation: 5837
You need to use criteria.add(Restrictions.in("identifier", ids));
and your ids
should be a collection like an ArrayList
.
Just noticed that your ids
is already a List, you can directly use Restrictions.in
.
Upvotes: 3