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.  [ 2 posts ] 
Author Message
 Post subject: Filtering a collection
PostPosted: Fri Nov 03, 2006 11:56 am 
Beginner
Beginner

Joined: Wed May 31, 2006 9:24 am
Posts: 22
Hi there, I have a collection of comments that I wish to filter. The collection has Parent and Children objects of the same type (ie. it is a hierarchy of objects).

I have tried to filter the collection as follows:

Code:
return (ArrayList)Repository.Instance.ActiveSession.Filter(this.AuctionComments, "WHERE Count(this.Parents) = 0");


but this generates the following error:

Code:
NHibernate.QueryException: unindexed collection before [] [WHERE Count(this.Parents) = 0] at NHibernate.Hql.PathExpressionParser.PrepareForIndex(QueryTranslator q) at NHibernate.Hql.PathExpressionParser.End(QueryTranslator q) at NHibernate.Hql.WhereParser.DoPathExpression(String token, QueryTranslator q) at NHibernate.Hql.WhereParser.DoToken(String token, QueryTranslator q) at NHibernate.Hql.WhereParser.Token(String token, QueryTranslator q) at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q) at NHibernate.Hql.PreprocessingParser.Token(String token, QueryTranslator q) at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q) at NHibernate.Hql.QueryTranslator.Compile() at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar) at NHibernate.Hql.FilterTranslator.Compile(String collectionRole, ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar) at NHibernate.Impl.SessionFactoryImpl.GetFilter(String filterString, String collectionRole, Boolean scalar) at NHibernate.Impl.SessionImpl.GetFilterTranslator(Object collection, String filter, QueryParameters parameters, Boolean scalar) at NHibernate.Impl.SessionImpl.Filter(Object collection, String filter, QueryParameters parameters) at NHibernate.Impl.SessionImpl.Filter(Object collection, String filter)


Can anyone tell me if it is possible to filter a collection in this way, and a suitable where clause if so?

AHA, Ben :)

Hibernate version:
1.0.2.0

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="SoleBidder.Domain.Classes" assembly="SoleBidder.Domain" default-access="field.camelcase">
   <class name="AuctionComment" table="`AuctionComment`">
      <jcs-cache usage="read-write" />
      <id name="Id" column="AuctionCommentId" type="Int32" unsaved-value="0">
         <generator class="identity" />
      </id>
      <bag name="Parents" table="AuctionCommentHierarchy" inverse="true"  lazy="true" order-by="ParentAuctionCommentId" cascade="none">
         <key column="AuctionCommentId" />
         <many-to-many class="AuctionComment" column="ParentAuctionCommentId" />
      </bag>
    <bag name="Children" table="AuctionCommentHierarchy" lazy="true" order-by="AuctionCommentId" cascade="none">
      <key column="ParentAuctionCommentId" />
      <many-to-many class="AuctionComment" column="AuctionCommentId" />
    </bag>
      
      <property name="Name" column="Name" type="String" not-null="true" />
      <property name="Subject" column="Subject" type="String" not-null="false" />
      <property name="Message" column="Message" type="String" not-null="false" />
      <property name="PostDate" column="PostDate" type="DateTime" not-null="true" />
      <many-to-one name="Auction" column="AuctionId" class="Auction" not-null="true"/>
   </class>
</hibernate-mapping>


Name and version of the database you are using:
SQL Server 2000
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 12:13 pm 
Beginner
Beginner

Joined: Wed May 31, 2006 9:24 am
Posts: 22
I have managed to resolve this by doing the following:

Code:
                string hql = @"from AuctionComment ac LEFT OUTER JOIN ac.Parents acp
                    WHERE IsNull(acp.Id, 0) = 0";

                IQuery qry = Repository.Instance.ActiveSession.CreateQuery(hql);
                return (ArrayList)qry.List();


Still would be interested to know if it is possible using my first method though!

Cheers, Ben


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