-->
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.  [ 2 posts ] 
Author Message
 Post subject: Saving a query for later use (maybe a detached criteria)
PostPosted: Thu Feb 23, 2006 1:32 pm 
Newbie

Joined: Fri Mar 11, 2005 7:22 pm
Posts: 10
On a web UI, lets say the user can fill in values into fields to perform searching on items. (color, size, style..etc)
After filling in the form, the user will then hit the search button to get the list of items that fits the search criteria.

Now, lets say the user wants to save that search, so he/she can execute it later on. ie label it as.. "summer clothes I want", so any time they want to they can click on that link and it will return the results they previously searched upon. Now there can be two types of saving, the query itself, or the results it brings back.. but i'll not address that here.

Question is: from the search form, I could create a sql string by hand (HQL) like "FROM classpath.Clothes clothes where clothes.color = 'red' ..blah blah.. and then save this to the database. But this would require me to check for apostrophes in the strings, and format dates to a certain sql way.

Or, using a detached criteria, and building it from the form. Is there a way to save that criteria to the database? possibly serialize the object and save it as a blob? If this can be done, how about in Hibernate 4.0.. the seralization of the criteria can use a different serial id causing exceptions. I also searched and wondered if there was a way to extract the sql out of a detached criteria, so it can be saved for later us.

Hope this makes some sense.
Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 12:50 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
DetachedCriteria are serializable, so you can use that to save it to the DB.
DetachableCriteria.toString also produces sensible output, you can generate HQL from it, though you'll have to strip off a lot of injected class names etc.

If you're brave, you could access DetachedCriteria's internal CriteriaImpl and shove it through CriteriaQueryTranslator. No idea what comes out the other side, though.


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