-->
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.  [ 4 posts ] 
Author Message
 Post subject: Counting records with Criteria object
PostPosted: Thu Mar 04, 2004 8:34 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
i'm trying out a criteria build dynamically from information i get from say a beaninfo object.

say A-->C one to many. i want to add an expression such that i want results only if A.getMultiC() (which results a List of Cs) has more than one element in it. now i 'wish' i could add something like this but this results in a ambiguous query.

Code:
Criteria c = s.createCriteria(ClassA.class)
  .add(Expression.like("testString", "Hello%"))
  .add(Expression.gt("multiC", new Integer(1)));


if i add "multiC" with .createCriteria() then of course it will introspect each of the list elements but that's not what i'm looking for.

probably just my usage issue?

regards
ravi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 12:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't understand why this doesn't work:

Code:
s.createCriteria(ClassA.class)
  .add(Expression.like("testString", "Hello%"))
  .createCriteria("multiC")
  .list();



Did you try it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 12:45 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
yes that will work to find all As which don't return an empty list for getMultiC().

my purpose is to make a count available where i want to be able to add a criteria using the list size as the property (e.g. "multiC.size" >= n).

now i tried to add a custom method on ClassA as getMultiCSize() that simply returns the list size (unsafe) and tried
Code:
Expression.ge("multiCSize", n)
but that didn't really work out.

suggestions?
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 2:05 am 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
hmm, no luck with this. i tried two different ways but i couldn't emulate what i can do with OQL to the effect of "cat.kittens.size > 2".

anyone tried this?


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