-->
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.  [ 5 posts ] 
Author Message
 Post subject: Concept: what is "Alias" and "Projection'? C
PostPosted: Tue Jul 04, 2006 9:17 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
This is a conceptual question, please feel free to point me to any tutorials or docs that explain this, but I haven't found them. I can RTFM and read the APIs, but only when I understand the concepts behind the terms.

I am well versed in SQL functionality and DB concepts, so if anyone can explain Alias and Projection in terms of joins, group bys, AS's, and other terms I would appreciate it.

Specifically, I am playing with the Criteria API.

Set Alias seems to be doing some joins and also setting an "AS" to refer to the joined table later. Is the entirety of it?

The Projection concept is a lot bigger and I really dont get it. It seems to be some kind of wrapper that can hold many different types of values to be held later. Those types of values are often aggregate values and/or group-by clauses, but can also be arbitrary SQL statements. Huh?

Thanks again!

_________________
_________________
dan

If what I say is helpful, please rate the post as such by clicking 'Y'. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 11:13 am 
Newbie

Joined: Wed Jul 05, 2006 8:49 am
Posts: 7
Location: Zurich
With projection you can do the things you can do in the select part of an SQL query.

Alias is like the AS statement in SQL but it may force a join in some cases (as far as I know).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 12:44 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
Quote:
With projection you can do the things you can do in the select part of an SQL query.


More specifically... what does that mean?

Quote:
Alias is like the AS statement in SQL but it may force a join in some cases (as far as I know).


It seems like sometimes it does and sometimes it doesn't which is why I am trying to understand conceptually what an Alias is, so that I can understand better.

_________________
_________________
dan

If what I say is helpful, please rate the post as such by clicking 'Y'. I appreciate it.


Top
 Profile  
 
 Post subject: projections
PostPosted: Thu Jul 06, 2006 1:17 am 
Beginner
Beginner

Joined: Thu Jun 23, 2005 4:11 pm
Posts: 24
projections basically define what columns will be returned whether they are a property or possibly the result of an aggregate function like sum() or avg()

the example in the docs

List results = session.createCriteria(Cat.class)
.setProjection( Property.forName("name") )
.add( Property.forName("color").eq(Color.BLACK) )
.list();

I believe would return one column "name" with names of all cats with color == black.


Top
 Profile  
 
 Post subject: EASY HQL EXAMPLE -- howto in Criteria
PostPosted: Thu Jul 06, 2006 3:27 am 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
I have read the docs. Here is an example of a question I have that i cant find covered by the docs, which leads me to try and understand the meaning of "Projection":

How can i do an Order by of a Grouping expression when i dont want to return the grouping?

in HQL: select cat from Cat cat order by size(cat.kittens) desc

Can anyone explain to me how to express that in Criteria API?

Trying: criteria.addOrder(Order.desc("size(kittens)");
throws:
org.hibernate.QueryException: could not resolve property: size(kittens) of: ..Cat

So I assume I have to use Projections for the aggregate size, but I dont want it in my select statement.

Or, what if instead of "size(..)" being an aggregate query, it was a DB function like "FLOOR(..)"? Would that also use a Projection? (a SQLProjection?)


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