-->
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.  [ 3 posts ] 
Author Message
 Post subject: Filtering an HQL Query with Criteria API?
PostPosted: Mon Feb 20, 2006 6:02 am 
Newbie

Joined: Tue Dec 09, 2003 1:59 pm
Posts: 5
I'm using Hibernate in an application where I have 2 main requirements:
1. I need to make a query in hql, wich I store in metadata (xdoclet) giving it a name
2. I need to use this query by name AND filter it afterwards (let the final user apply additional filters to the original query results)

I would like to do something like:
Query q = getSession().getNamedQuery(queryName);
q.addCriteria(Expression.like(propertyName, propertyValue));
result = q.list();

I've tried filters, but they don't allow to filter query results, but persistent collections.

Is it possible to use the Criteria API against a query stored by name in HQL? In such case, how? If not, should I filter the query modifying the HQL string adding and clauses by hand? Is there any other aproach I'm missing?

Thanks in advance,
Jordi


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 5:56 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Class filters do allow you to filter query results. Section 17 of the ref docs explain it.

The only other way to filter results before executing the HQL query is to build the HQL query dynamically. You can do this even if you've created a named query in xdoclet (or a mapping file) by getting the named query, calling getQueryString on it, adding to the string as necessary, and creating a new query from that string.

Your only other option is to filter the results, in code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 8:35 am 
Newbie

Joined: Tue Dec 09, 2003 1:59 pm
Posts: 5
Since I'm usinig version 2.1.8 I have only the 2 last options, but they are absolutely vaild.

Many thanks!
Jordi


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