-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria: Order by whether or not a collection is empty
PostPosted: Wed Oct 04, 2006 3:10 pm 
Regular
Regular

Joined: Wed Feb 15, 2006 9:09 pm
Posts: 76
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.0cr4

Name and version of the database you are using: Oracle 10gR2

I have something like the following:

Code:
Criteria criteria = session.createCriteria( Cat.class );
criteria.add( Restrictions.isEmpty( "kittens" ) );
List kittenlessCats = criteria.list();
...


Which is pretty darn cool (ie: I'm still learning :). Now if I query all cats, is it possible to ORDER BY whether or not a Cat has kittens, so all kittenless cats appear first (asc), or last (desc) in the result set?

By the way, here's what I'm doing now... it's kind of ugly, and produces messy SQL (though I'm not sure if there's a better way... anyone?):

Code:
<property name="isMember" insert="false" update="false">
  <formula>
    ( select 1 from cat_kitten_assoc cka where cka.kitten_id = kitten_id and rownum &lt; 2 )
  </formula>
</property>


Then I declare a "Boolean isKitten" in the Kitten class (I changed the example a bit, essentially it's a Cat<->CatKitten<->Kitten relationship, many-to-one-to-many, for illustrative purposes). So "isKitten" is either going to be null, or Boolean.TRUE :). AND Oracle'll order by it.

Ideas?

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.