-->
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.  [ 7 posts ] 
Author Message
 Post subject: Creating detached queries for HQL
PostPosted: Wed Sep 14, 2005 12:38 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
I'm creating a three tier web application, where I create my queries on the web tier but execute them on the backend tier. As far as I'm using Criteria queries everything is fine. I create a DetachedCriteria, pass it to the BackendTier, add the session, do the query and get my result.

But sometimes I would like to execute HQL queries. Cause the WebTier is unaware of any Session, I cannot use Session.createQuery(), so I'm looking for something like a detached Query. Is there something like the DetachedCriteria for HQL? Or is there someway I can create my own Session Implementation, if it's possible at all?

Hibernate version: 3.05


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 12:58 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
I am not clear why you need/should create queries in web tier.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 1:02 pm 
Newbie

Joined: Wed Sep 14, 2005 12:17 pm
Posts: 13
Since HQL is just a string, you could create an implementation of the Query interface (say, QueryImpl) that holds the query string and a map of all the parameters that you're providing to it.

Pass the QueryImpl up to your backend tier and then have some generic handler on the backend tier to transfer the query and all parameters into a query created from the session object.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 1:20 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
Exposure hibernate specific stuff to web tier is not a good idea.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:03 am 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
I think it's another discussion if you should expose hibernate specific stuff to the web. There is much discussion about layering in the java world, sometimes i think java people are making thinks more complicated than necessary.
Layering is a good practice but it has it's limits. In practice I've never seen a project (in any company) where I could change the WebTier without any changes on the business tier. What would you do, if you don't want expose your query to whe tier? Your query will be defined by user input, so you have to transfer it in someway to the business tier. Would you create a "meta query language" of the user input and send this to you business tier?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 12:16 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
I understand your points.

You can create plain search criteria value objects to hold search criterion that the user entered, and then pass them to your persistence layer. The persistency layer can dynamic build a Hibernate Criterion based on the collected use input, or use the data to populate your named HQL query. Now your web tier has no knowlege of the persistence mechanism. For some reason, if you decide to use a different mechanism, say use OODB or plain JDBC to access a RDMS, your web tier do not have to change.

Hope this is helpful.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject: Re: Creating detached queries for HQL
PostPosted: Mon Aug 08, 2011 8:46 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
I have a different use case for detached Query objects: Running a variation of a complicated query built from earlier user input.
E.g. rerunning the query because the user now wants the full result set instead of just the first 1000 rows (we have that e.g. for exporting to Excel).
The complication is that the new run would be in a different Hibernate session (think transient networking problems, or an Oracle server that will occasionally throw exceptions at perfectly normal SELECT statements).
We could rebuild the Query each time we need it, but storing the user input for that can be quite complicated (user input can contain range selection or enum subsets, that's complicated to store).


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