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 < 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.