Hi all,
We're experiencing a strange problem in one of our deployed webapplication when fetching data from our database using HQL. It seems that when using a property-value on which to search for that contains a specific number of comma's prior to a dot (.), NHibernate returns an error when executing the HQL (see exceptions below). This occurs in a semi complex webapplication with a rich domain model and complex hierarchy.
A Customer has one or more EndCustomers.
An EndCustomer has a one-to-one relation with a Company.
A Company has a one-to-one relation with an Address.
What we are trying to do is fetch an EndCustomer from our database based on the property-value of an Address.
Success: HQL: select persistentType from EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B,C'
Success: HQL: select persistentType from EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B,C test'
Success: HQL: select persistentType from EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B C test.test'
Success: HQL: select persistentType from EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B C test.test D,E test'
Success: HQL: select persistentType from EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B C test test'
Failure: HQL: select persistentType from EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B,C test.test'
My question is why the last HQL is giving us an error when it's being executed by NHibernate? 2 Comma's prior to one dot (.). It seems that every other combination (however, the list is not complete) is working correctly. Can somebody explain this? And even better provide a solution for this strange behaviour/problem.
Main Exception
--------------
Type : NHibernate.QueryException, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc
Message : Incorrect query syntax [select persistentType from Domain.Customer.EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B,C test.test' ]
Source : NHibernate
Help link :
QueryString : select persistentType from Domain.Customer.EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B,C test.test'
Data : System.Collections.ListDictionaryInternal
TargetSite : Void Compile()
Stack Trace :
at NHibernate.Hql.QueryTranslator.Compile()
at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar)
at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)
at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List()
Inner Exception
---------------
Type : System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Item has already been added. Key in dictionary: 'persistentType' Key being added: 'persistentType'
Source : mscorlib
Help link :
ParamName :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void Insert(System.Object, System.Object, Boolean)
Stack Trace :
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at NHibernate.Hql.QueryTranslator.SetAliasName(String alias, String name)
at NHibernate.Hql.FromParser.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()
Kind regards,
Felix
SDB Software Development
The Hague, The Netherlands
www.sdb.nl