Hi there!

In my understanding, HQL does NOT accept aliases in the select clause.  It does 
accept aliases in the from and any join clauses, though.  You may have seen 
samples like this:

"select motherCat.Id, c.Id from Cat c join c.Mom as motherCat"

As you can see, the aliases are in the from and join clauses.  This allows you 
to easily reference them in the select clause.

There is really no point in adding aliases in the select clause as you 
attempted to do, because NH does not allow you to reference the returned 
results by alias, just by the position in the IList<object[]>.

Does that help?

-tyler burd

________________________________
From: [email protected] [mailto:[email protected]] On Behalf Of 
Fethi Gürcan
Sent: Monday, March 30, 2009 7:37 AM
To: nhusers
Subject: [nhusers] HQL query doesnt accept column aliases??

Hello,

i'm newbie in nhibernate and i've 2 simple question.

1) i'm trying some simple HQL queries for learning querying in hibernate.

                            "select c.Id, c.PlakaNo, c.Name from Il c"        
(selected columns are less than the table's original, so it returns 
IList<object[]>)

    this is a simple query that i run.

But when i add some aliases like this: "select c.Id as xx, c.PlakaNo as yy, 
c.Name as zz from Il c"

it throws this exception : " ',' expected in SELECT before:as [select c.Id as 
xx, c.PlakaNo as yy, c.Name as zz from Il c] "

i see many samples that uses column aliases.

what's the point that i missed?

and after that.

2) It seems i have to use IResultTransformer for "custom" query results (for 
search results, lists etc.) for trnasforming well defined generic list<DTO>.
(and it seems Transformers.AliasToBean() needs aliases for work right?)

Note: i can't run the AliasToEntity() cause question (1). But i'd write my own 
custom IResultTransformer class successfully. But i think it is not the good 
choice in many cases.
(this approach needs Trasformer for each individual DTOs)

First: is it the main approach for results like this example?
Second: or what is the main approach that are you using?

Thanks









--
Fethi Gürcan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to