-->
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: hql wired error
PostPosted: Mon Feb 01, 2010 8:08 pm 
Newbie

Joined: Mon Feb 01, 2010 7:51 pm
Posts: 4
hi, i'm new to the forum. i'm doing now the "summer of nhibernate" tutorial (even though we're in the winter...)
anyway i found weird error using hql.

this query works perfect :

return session.CreateQuery("from Customer e where e.FirstName=:fn")
.SetString("fn",firstname).
List<Customer>();


but this one dose'nt work:

return session.CreateQuery("select from Customer e where e.FirstName=:fn")
.SetString("fn",firstname).
List<Customer>();


the only difference ,as you can see, is the word "select" in the beginning of the query.

what's the reason for that?

i'm using the newest version of nhibernate (2.1.2)


Top
 Profile  
 
 Post subject: Re: hql wired error
PostPosted: Tue Feb 02, 2010 6:44 am 
Newbie

Joined: Mon Aug 31, 2009 6:30 am
Posts: 9
Location: Bolzano, Italy
Hi,

Try "select e from Customer e where e.FirstName=:fn" as query string.

This should do the trick.

Explanation:
The "e" immediately after the select specifies that you want to retrieve all objects of type Customer that satisfy the where clause. If you completeley omit it, it would be as if you selected "SELECT FROM DBTABLE" in SQL. In such case, you would need to put a "*" after the SQL SELECT.
Alternatively, you could also select single properties using the HQL select query, e.g. (I assume you Customer class has got a property name): select e.Name from Customer where e.FirstName=:fn.

Hope this helps.

I also started a small tutorial series about nhibernate on my blog, and you are kindly invited to also have a look there.

Best regards,
Martin W. Angler
http://angler.wordpress.com (blog about c#, nhibernate, Pex, Code Contracts, etc.)

_________________
Tutorials and solved problems under:
http://angler.wordpress.com


Top
 Profile  
 
 Post subject: Re: hql wired error
PostPosted: Wed Feb 03, 2010 11:48 am 
Newbie

Joined: Mon Feb 01, 2010 7:51 pm
Posts: 4
thanks!
did the job...


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.