-->
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.  [ 4 posts ] 
Author Message
 Post subject: Set containment: how to use Criteria
PostPosted: Mon Aug 17, 2009 6:05 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
public class Merchant {
public enum Service {
A,
B,
C,
D,
E,
F,
}

@CollectionOfElements(fetch=FetchType.LAZY)
@JoinTable(name = "Merchant_Service",
joinColumns = {@JoinColumn(name = "mId")})
@Column(name="service", nullable=false, columnDefinition="smallint(2)")
@Enumerated(value=EnumType.ORDINAL)
public Set<Service> getServices() {
return services;
}

}

Every merchant provides a set of Service, such as {A, B, D}, {A, D, F}, etc.

Using Criteria API:
Query: return all Merchants that provide service A and D, ie, their services containing subset {A, D}.

Restrictions.contains(propertyName, collectionValue).

The criteria API does not provide such method.

Thanks for help.
Dave


Top
 Profile  
 
 Post subject: Re: Set containment: how to use Criteria
PostPosted: Mon Aug 17, 2009 9:36 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Check out this little tutorial on the topic for some insight into the Hibernate Criteria API:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=09howtousethecriteriaapi

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Set containment: how to use Criteria
PostPosted: Mon Aug 17, 2009 11:27 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Hi Cameron,
Thanks for reply. I looked at the article, but it did not talk about the HOW-TO for "the set containment".
If you can help me, it would be great.

Thanks,
dave


Top
 Profile  
 
 Post subject: Re: Set containment: how to use Criteria
PostPosted: Sun Oct 18, 2009 7:27 am 
Newbie

Joined: Tue Aug 26, 2008 12:18 pm
Posts: 9
Hi.

you can use the feature of criterias, which allows you to navigate associations using createAlias() or createCriteria(). Check
https://hibernate.bluemars.net/hib_docs ... teria.html, the second example.

I have answered similar question in this topic, so try ty check out my answer at:

viewtopic.php?f=1&t=999756

Hope it helps.
stue

_________________
Arguing on the Internet is like running in the Special Olympics.

Even if you win, you’re still retarded. :P


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.