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.  [ 6 posts ] 
Author Message
 Post subject: NHibernate.QueryExpection
PostPosted: Sat Dec 02, 2006 11:18 pm 
Newbie

Joined: Tue Nov 28, 2006 2:23 am
Posts: 7
I'm running the following query to try and load the rows for my database (SQL Server, 2005 i think),

System.Collections.IList people;

(other code)

string HQL = "from person as p order by p.Name asc";
people = session.Find (HQL);

I'm getting the following error:
NHibernate.QueryException: unexpected token : as [from person as p order by p.Name asc]

I'm using visual studio express edition 2005, like i said i'm pretty sure its sql server 2005.

mapping file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns ="urn:nhibernate-mapping-2.0">
<class name ="ListQuery.Persons, ListQuery" table="person">
<id name="Id" column="ID">
<generator class ="increment"/>
</id>
<property name="Name" column ="Name"/>
<property name="Birthday" column="BirthDate"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 03, 2006 3:43 am 
Newbie

Joined: Tue Nov 28, 2006 2:23 am
Posts: 7
something must have been wrong with a mapping file, cause I copied the statements into another NHibernate program that worked and then the statements worked, so I don't know other than a mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 03, 2006 1:55 pm 
Newbie

Joined: Mon Mar 27, 2006 10:24 am
Posts: 8
Location: Malmoe, Sweden
try
Code:
string HQL = "from Person as p order by p.Name asc";

nHibernate is case sensitive so Person and person are not the same (it's the class name you use not the table name)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 03, 2006 2:19 pm 
Newbie

Joined: Tue Nov 28, 2006 2:23 am
Posts: 7
actually according to the documenation HQL is case insensitive.

Quote:
11.1. Case Sensitivity
Queries are case-insensitive, except for names of .NET classes and properties. So SeLeCT is the same as sELEct
is the same as SELECT but Eg.FOO is not Eg.Foo and foo.barSet is not foo.BARSET.


the pdf can be found at
http://www.hibernate.org/hib_docs/nhibe ... erence.pdf

person was the name of my table and Name was a property but you were right in that person is not the same as Person nor is name equal to Name so long as its a property and like i said, i copied the hql statement into another working nhibernate soluntion and it worked but thanks for the response.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 2:04 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 5:33 pm
Posts: 28
Location: Chicago, IL
As you posted, the queries are case insensitive "except for names of .NET classes and properties." In the HQL query below, "Persons" is a .NET class name, not a table name. The same as Name is a property on the Person class, not a column in the table.

Code:
from Persons as p order by p.Name asc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 9:50 pm 
Newbie

Joined: Tue Nov 28, 2006 2:23 am
Posts: 7
ok, I thank you for the posts, but the problem as been solved so no futher posts are needed.


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