I have a collection of composite-elements which are the property Text of a class called Product. I am trying to use HQL to find objects which have a certain word in the Text property of one of the composite elements. I am using the following HQL:
Code:
FROM Foo.Ecommerce.Catalogue.Product AS p WHERE p.Text['Description'].Text LIKE '%incorporated%'
and I get the following exception:
Code:
illegally dereferenced collection element [FROM Foo.Ecommerce.Catalogue.Product AS p WHERE p.Text['Description'].Text LIKE '%incorporated%']
Is it actually possible to do this sort of query using HQL or ICriteria? Any suggestions would be much appreciated.
Hibernate version: NHibernate 1.2.0.CR2
Mapping documents:Code:
<map name="Text" access="field.camelcase" table="tbl_ecom_cat_product_text" collection-type="Foo.Core.ObservableDictionary`2[[System.String],[Foo.Ecommerce.Catalogue.CatalogueText, Foo.Ecommerce]], Foo.Core">
<key column="prod_id" />
<index column="`key`" type="String" />
<composite-element class="Foo.Ecommerce.Catalogue.CatalogueText, Foo.Ecommerce">
<property name="Text" column="`text`" type="String" update="true" insert="true" access="property" />
<property name="DisplayAsHtml" column="display_html" type="Boolean" update="true" insert="true" access="property" />
<property name="EditAsHtml" column="edit_html" type="Boolean" update="true" insert="true" access="property" />
</composite-element>
</map>
Code between sessionFactory.openSession() and session.close():Code:
string sql = string.Format( "FROM Product AS p WHERE p.Text['Description'].Text LIKE '%{0}%'", word );
IQuery query = session.CreateQuery( sql );
return query.List<Product>();
Full stack trace of any exception that occurs:Code:
[QueryException: illegally dereferenced collection element [FROM Foo.Ecommerce.Catalogue.Product AS p WHERE p.Text['Description'].Text LIKE '%incorporationg%']]
NHibernate.Hql.Classic.WhereParser.GetElementName(CollectionElement element, QueryTranslator q) in D:\Shared\Nhibernate\NHibernate\Hql\Classic\WhereParser.cs:184
NHibernate.Hql.Classic.WhereParser.ContinuePathExpression(String token, QueryTranslator q) in D:\Shared\Nhibernate\NHibernate\Hql\Classic\WhereParser.cs:625
NHibernate.Hql.Classic.WhereParser.Token(String token, QueryTranslator q) in D:\Shared\Nhibernate\NHibernate\Hql\Classic\WhereParser.cs:220
NHibernate.Hql.Classic.ClauseParser.Token(String token, QueryTranslator q) in D:\Shared\Nhibernate\NHibernate\Hql\Classic\ClauseParser.cs:104
NHibernate.Hql.Classic.PreprocessingParser.Token(String token, QueryTranslator q) in D:\Shared\Nhibernate\NHibernate\Hql\Classic\PreprocessingParser.cs:147
NHibernate.Hql.Classic.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q) in D:\Shared\Nhibernate\NHibernate\Hql\Classic\ParserHelper.cs:32
NHibernate.Hql.Classic.QueryTranslator.Compile() in D:\Shared\Nhibernate\NHibernate\Hql\Classic\QueryTranslator.cs:295
NHibernate.Hql.Classic.QueryTranslator.Compile(IDictionary replacements, Boolean scalar) in D:\Shared\Nhibernate\NHibernate\Hql\Classic\QueryTranslator.cs:259
NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow, IDictionary enabledFilters) in D:\Shared\Nhibernate\NHibernate\Impl\SessionFactoryImpl.cs:520
NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar) in D:\Shared\Nhibernate\NHibernate\Impl\SessionImpl.cs:1786
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results) in D:\Shared\Nhibernate\NHibernate\Impl\SessionImpl.cs:1753
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) in D:\Shared\Nhibernate\NHibernate\Impl\SessionImpl.cs:1736
NHibernate.Impl.QueryImpl.List() in D:\Shared\Nhibernate\NHibernate\Impl\QueryImpl.cs:87
Foo.Ecommerce.Web.Catalogue.ProductRepeater.CreateCustomCollection() in D:\Shared\Foo\Ecommerce\Foo.Ecommerce.Web\Catalogue\Product\ProductRepeater.cs:55
Foo.Ecommerce.Web.Catalogue.ProductRepeater.CreateCollection() in D:\Shared\Foo\Ecommerce\Foo.Ecommerce.Web\Catalogue\Product\ProductRepeater.CodeSmith.cs:104
Foo.Ecommerce.Web.Catalogue.ProductRepeater.GetCollection() in D:\Shared\Foo\Ecommerce\Foo.Ecommerce.Web\Catalogue\Product\ProductRepeater.CodeSmith.cs:50
Foo.Web.AbstractRepeater.GetItems() in D:\Shared\Foo\Framework\Web\Foo.Web\Repeater\AbstractRepeater.cs:491
Foo.Web.AbstractRepeater.CreateChildControls() in D:\Shared\Foo\Framework\Web\Foo.Web\Repeater\AbstractRepeater.cs:353
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360
Name and version of the database you are using:Microsoft SQL Server 2003
The generated SQL (show_sql=true):None
Debug level Hibernate log excerpt:Code:
NHibernate.Impl.SessionImpl: find: FROM Product AS p WHERE p.Text['Description'].Text LIKE '%incorporated%'- [19] DEBUG [(null)]
NHibernate.Engine.QueryParameters: named parameters: {}- [19] DEBUG [(null)]
NHibernate.Hql.Classic.QueryTranslator: compiling query- [19] DEBUG [(null)]
A first chance exception of type 'NHibernate.QueryException' occurred in NHibernate.DLL
Additional information: illegally dereferenced collection element
A first chance exception of type 'NHibernate.QueryException' occurred in NHibernate.DLL
Additional information: illegally dereferenced collection element
An exception of type 'NHibernate.QueryException' occurred in NHibernate.DLL but was not handled in user code
Additional information: illegally dereferenced collection element