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.  [ 3 posts ] 
Author Message
 Post subject: Urgent problem fetching data using HQL
PostPosted: Wed Apr 04, 2007 10:05 am 
Newbie

Joined: Wed Apr 04, 2007 10:00 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 7:37 pm 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
I have no idea why the problem show up. Have you tried parameterized query?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 6:12 am 
Newbie

Joined: Wed Apr 04, 2007 10:00 am
Posts: 2
Canton,

Thanks for your reply. I don't see how a parameterized query would solve the problem. Or has it something to do with escaping special characters, like the comma and dot? To me it looks more like a parsing error in NHibernate when it tries to build the SQL-statement based on the HQL created by us.

I should bring this issue to the attention of the builders of NHibernate, as I would guess they have the knowledge and tooling available to easily test the problem/behaviour I describe. That's why they invented unittests :)

Summary of source code:
string hql = "select persistentType from EndCustomer as persistentType WHERE persistentType.Company.Address.AddressString = 'A,B,C test.test' ";

IQuery query = session.CreateQuery( hql);
query.SetFirstResult ( first );
query.SetMaxResults ( max );

return query.List();

The code above results in the error as described in my previous post. When using the same code for the other HQL statement (see previous post), all works just fine.

Felix.


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