-->
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: Help with HQL join
PostPosted: Mon Apr 23, 2007 3:34 pm 
Newbie

Joined: Wed Feb 14, 2007 12:44 pm
Posts: 2
I have two entities (Articles and Categories) that have a many to many association between them. In order to be able to show related articles to users, I'm trying to write a query that will return recent articles that belong to one of the categories that the current article is in. Writing the sql to do this is straight forward enough but I can't seem to get the HQL right.

Code:
public IList<Article> GetRelatedArticles(Article relatedArticle, int count)
{
            IQuery query =
                session.CreateQuery(
                    @"select article from Article article
                        join article.Categories category   
                    where article.Publish = 1 and article.PublishDate < :now
                        and category in (select relatedArticle.Categories from Article relatedArticle where relatedArticle = :relatedArticle)   
                    order by article.PublishDate DESC")
                    .SetDateTime("now", DateTime.Now)
                    .SetEntity("relatedArticle", relatedArticle)
                    .SetMaxResults(count);
            return query.List<Article>();
}


When I run this query I get an NHibernate exception with the following message.

"unindexed collection before [] [select article from AroundTheRings.Model.Article article
join article.Categories category
where article.Publish = 1 and article.PublishDate < :now
and category in (select relatedArticle.Categories from AroundTheRings.Model.Article relatedArticle where relatedArticle = :article)
order by article.PublishDate DESC]."

Can someone shed some light on what I'm doing wrong here?


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.