-->
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.  [ 4 posts ] 
Author Message
 Post subject: using "select new map" with Criteria
PostPosted: Wed Jun 28, 2006 1:08 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
Is there a way to use the "select new map" when using Criteria to execute a query?

The "select new map" is perfect for what I want to do. I just need a few fields returned some of which may be nested deeply in the tables, and I don't have classes for the underlying tables.

"select new map" works fine when I use a Query. My problem is that my application has a search page with a bunch of fields that the user can enter values for that will end up in the where clause. If they do not enter a value for a field the param associated with that field should not be included in the where. If I use Query for this, I will get an exception that all parameters are not set. I'm not real keen on building the queryString dynamically. Criteria works real well for this. If the field is null, I don't add a Restriction on the Criteria for that field.

So "select new map" with Criteria will do the trick for me. Can it be done?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 6:25 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Not really. Criteria queries load objects, not groups of scalars. You can force scalar results through clever use of projections. For example, if you select max(field) on a Criteria where you're specifying the id (so only one row is going to be returned), then you get the field value (max value of all one values is the value). However, this is very inefficient, compared to the HQL equivalent.

Report queries are best done as HQL or SQL.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 5:53 pm 
Beginner
Beginner

Joined: Mon Aug 01, 2005 3:51 pm
Posts: 22
I think that I can use Filter with Query to do the trick


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 01, 2006 3:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
criteria supports report querying just a good as HQL/SQL.

to have "select new" functionallity look at resulttransformer API (we also have a blog about - search for transformer)

_________________
Max
Don't forget to rate


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