-->
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.  [ 3 posts ] 
Author Message
 Post subject: Restriction expression to test collection-valued property?
PostPosted: Tue Jul 10, 2007 11:17 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Hi,

I have...

1) persistent objects of a class Event...

2) which has a Set property "types"...

3) whose values are persistent objects of a class EventType...

4) and EventType has a String property "name"

And all this works fine. But now I need to build a query using the Criteria interface, and I need a restriction that is satisfied if the Event's "types" property contains the given (as a parameter) EventType.

Or better yet... if the Event's "types" property contains the EventType whose "name" is the given String.

I can't find anything in Restriction that does the job (Hibernate3). Any ideas?

thx a lot,
—ml—


Top
 Profile  
 
 Post subject: try this.
PostPosted: Wed Jul 11, 2007 1:34 am 
Newbie

Joined: Wed Mar 14, 2007 2:21 am
Posts: 5
Doesn't this work?

Code:
List cats = sess.createCriteria(Event.class) 
    .createCriteria("types")
        .add( Restrictions.like("name", "any name") )
    .list();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 1:43 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Beautiful! That works perfectly, thanks a lot!
—ml—


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

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.