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
Hello thanks for the answers.
firstly, i can't realize why i need to select a new object? Actually what different between;
"select c from Cat c where .." and "select new Cat(c.x,c.y,c.z) from Cat c where ..."
Is it like below?:
- Might i write/use a alternative constructor of Cat with the x,y,z parameters? (i assume Cats have more porperties than x,y,z)
- Can i write any other (not mapped) simple class (e.g. CatHuman) with some properties. And "select new CatHuman(c.x,c.y,c.z) from Cat c where ..." and this query returns IList<CatHuman> right?.
- Actually i'm planning to use Criterias for most cases. can i "select new" in criterias?
- it seems i can use "select new" instead of IResultTransformer. right?
- "select new" really looks cool. any limitations? when i have to use IResultTransformer instead of "select new"?