-->
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.  [ 6 posts ] 
Author Message
 Post subject: Criteria API and count(*)
PostPosted: Tue Jul 20, 2004 2:13 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
Can I use the Criteria API to write a count(*) select?
If yes how? Unfortunalty the documentation does not talks about this.

Any thougths and advices are welcome ;).

Thx again for this fine product.

Bye
Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 2:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, this is not yet possible.


Top
 Profile  
 
 Post subject: HQL for Example#enableLike?
PostPosted: Tue Jul 20, 2004 5:46 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
michael wrote:
No, this is not yet possible.


Okay.

Is there a workaround for this in HQL?

Code:
select count(bla.id) where like :object


I really like the #enableLike Method of Example class. Is there a equvalent for this in HQL???

Thx
Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 7:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 7:54 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
michael wrote:
No :)


Would be nice feature for Hibernate3 , wouldn't it?

:-D

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject: easy to implement doing your own WildCardCountProjection
PostPosted: Thu Aug 11, 2005 10:41 am 
Newbie

Joined: Tue Mar 09, 2004 12:01 am
Posts: 9
For Hibernate 3.x, you just need to use the following projection:
Code:
new SimpleProjection() {
  public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) {
       return "count(*) as y"+position+"_";
  }
}


See CountProjection source code for more info, for example if you want to support distinct, or other features.

Another simple solution is to just use a SqlProjection.

Fabien Le Floc'h.


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