Created
November 14, 2012 22:53
-
-
Save juanpicado/4075433 to your computer and use it in GitHub Desktop.
Subquery Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("unchecked") | |
public List<TweetPoll> getTweetPollsbyHashTagNameAndDateRange( | |
final String tagName, | |
final SearchPeriods period) { | |
final DetachedCriteria detached = DetachedCriteria | |
.forClass(TweetPoll.class) | |
.createAlias("hashTags", "hashTags") | |
.setProjection(Projections.id()) | |
.add(Subqueries.propertyIn( | |
"hashTags.hashTagId", | |
DetachedCriteria | |
.forClass(HashTag.class, "hash") | |
.setProjection(Projections.id()) | |
.add(Restrictions.in("hash.hashTag", | |
new String[] { tagName })))); | |
final DetachedCriteria criteria = DetachedCriteria.forClass( | |
TweetPoll.class, "tweetPoll"); | |
criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached)); | |
criteria.addOrder(Order.desc("tweetPoll.createDate")); | |
criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE)); | |
// calculateSearchPeriodsDates(period, criteria, "createDate"); | |
return getHibernateTemplate().findByCriteria(criteria); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment