-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Is Restrictions.or usable across tables
PostPosted: Mon Apr 21, 2008 7:47 am 
Newbie

Joined: Tue Jan 15, 2008 4:11 am
Posts: 4
Location: Belgium
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.