-->
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: Hibernate Criteria and HQL re-elaboration
PostPosted: Mon Dec 05, 2005 8:16 am 
Newbie

Joined: Mon Dec 05, 2005 8:00 am
Posts: 5
Location: Rome
May be questions like this where already posted, but I couldn't find them searching the forum, so please pardon the re-post.

I'm trying to give to my development group a support class to simply paginate over a Criteria or Query results.

My Paginator class must extract from the Query or Criteria the SQL ready to be executed on the DB and use it as the FROM clause of a SELECT COUNT(*) to compute the results count.

So, for a given Criteria or Query with any parameter or criterion alredy setted and established, I want to execute:

Code:
StringBuffer buffer = new StringBuffer("select count(*) from (");
// the original Criteria/Query with fields/parameters replaced with actual values
buffer.append(")");
Iterator iterator = session.iterate(buffer.toString());
count = ((Integer)iterator.next()).intValue();


Or something which produces the same output... is there a clean solution?

Hibernate version: we are currently using 2.1.8, but we are ready to migrate to 3 so solutions for both are welcome.


Top
 Profile  
 
 Post subject: Not yet a response
PostPosted: Tue Dec 13, 2005 7:13 pm 
Newbie

Joined: Mon Dec 05, 2005 8:00 am
Posts: 5
Location: Rome
I'm sure I'm not the first one asking this question, but I received no answer... I thought the Hibernate developers, may be not all of them, were watching on this forum... I'm still investigating the problem and naturally I'm ready to put my hands in the dirty part...I'm not scared by the work.

I'm actually in the opinion the fastest solution is to "exactly" perform the same invocation calls the Hibernate session performs to translate a Query or Criteria into native SQL... but I really hope there is a cleaner solution, something like...

SessionFactory.convertToSQL(query);

or

SessionFactory.convertToSQL(criteria);


The main problem I faced is parameters substituition... any idea?!?


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.