Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Criteria setProjection result set

 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I'm new to Hibernate Criteria, and I'm stuck with a problem. I'm trying to perform a query, and then get only 2 columns.

So first step:


No problem, I get a List<Users> as a result, perfect.

Second step:

No problem either, I get a List<String>

Third step:


Here I've got the problem, now I get a List<Object> which I've read is the normal thing to get, so I want Users instead of objects. After some reading I discover that if I add a ResultTransformer I can get Users instead of Objects.

So I add:


And I get a List<users> but the users have no properties, no name or age.

So if I add instead:

I don't quite understand what this should give, but I just get a List<String> with one of the two User's properties.

I just don't understand what's going on. I just need both columns, I don't care if I have to deal with objects (don't know how to get information out of them) or Lists of Strings or whatever. I just need the information.

I would really appreciate some hints on this. Thanks!
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you say, in simple terms, what your query is supposed to get? What is it about the User that you are querying?

-Cameron McKenzie
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'ts really nothing specific. I'm just trying to perform searches and then performing projections on the resul set. I need to develop a really flexible module to query the database. So I need to now how to deal with the result set. If I'm not able to get results with just 2 columns in a really simple query, I can't imagine what will happen when I have joins and restrictions and everything.
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I finally found the answer here

It seems that you need to add aliases to the projections, as simple as that. Then it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic