Say I have a domain model
class Item {
Long id;
String name;
User seller;
}
class User {
Long id;
String name;
}
and database tables
ITEM (ID, NAME, SELLER_ID)
USER (ID, NAME)
Say I want to query for all items which have "apple" in it or which are owned by "King":
HQL:
from Item i, User u
where i.name ILIKE '%apple%' OR u.name ILIKE "King"
Is this constructable with Criteria?
I would write something like:
Criteria root = session.create(Item.class);
Criteria seller = root.createCriteria("seller");
Restriction r1 = Restrictions.ilike("name", "%apple%");
Restriction r2 = Restrictions.ilike("name", "%King%");
Normally, r1 would be added to root, and r2 to seller,
but how can I "or" those conditions?
_________________ Sincerely,
Joost Winne
|