-->
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.  [ 4 posts ] 
Author Message
 Post subject: simple HQL -> NHibernate.QueryException
PostPosted: Sat Sep 03, 2005 3:44 pm 
Newbie

Joined: Tue Aug 02, 2005 7:30 am
Posts: 8
Hi,
I'm running a simple HQL query, but I can't get it to work.
The statement is:

IList mp = session.Find("from Pharmaco.MedicalProduct");

resulting in a runtime error :
NHibernate.QueryException: undefined alias or unknown mapping:
Pharmaco [from Pharmaco.MedicalProduct]

I found a few other forum posts about this error, they seem to be related to mapping problems. However, I can simply load an object like this:
MedicalProduct mp = (MedicalProduct)session.Load(typeof(MedicalProduct), 1);
without any problems. So I think my mapping is OK.

Does anyone have any suggestion?
when I use "from MedicalProduct" instead of "from Pharmaco.MedicalProduct" I get a different error:
NHibernate.ADOException: could not execute query ---> System.Data.OleDb.OleDbException: The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

Is this a normal thing? (I guess not :)

many thanks,
Bert


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 03, 2005 5:12 pm 
Newbie

Joined: Tue Aug 02, 2005 7:30 am
Posts: 8
Ok,
I figures out why I get the second error (ADOException).
Nhibernate produces the following (simple!) SQL statement for ms access:

select medicalp0_.MPCOD as MPCOD, medicalp0_.NOTE as NOTE, medicalp0_.MPCV as MPCV, medicalp0_.HYR as HYR, medicalp0_.IRCOD as IRCOD, medicalp0_.POS as POS, medicalp0_.MPNM2 as MPNM2, medicalp0_.WADAF as WADAF, medicalp0_.WADAN as WADAN, medicalp0_.EQUIV as EQUIV, medicalp0_.MPNM as MPNM from MP medicalp0_;

however, it fails during execution. I checked it manually in access, and, I havn't got a clue why, but NOTE is marked as "a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."

So it seems that NOTE (which is the name of a tablecolumn) is a reserved word in access sql?
When I use the query builder of access,it indeed generates sql with [NOTE] instead of NOTE, of course nhibernate doesn't.

Changing the column name would be very hard due to sync issues.. but maybe there's another way out?
And could this have something to do with the first error I'm getting? (NHibernate.QueryException)

greets,
bert


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 04, 2005 4:49 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
You can use backticks (`) around the database field names in the mapping files. This way the field names will be quoted. I wouldn't be surprised though if this messes up some other thing in Access. It is really not supported very well.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject: Re: simple HQL -> NHibernate.QueryException
PostPosted: Sun Sep 04, 2005 11:39 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
And as you probably figure it out, you shouldn't use namespaces in your HQL queries:

bbloemen wrote:
IList mp = session.Find("from Pharmaco.MedicalProduct");

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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