-->
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: foo.asso is null or foo.asso.val=something
PostPosted: Tue Mar 29, 2005 1:27 pm 
Newbie

Joined: Wed Sep 29, 2004 10:36 am
Posts: 8
Location: Berlin, Germany
Hibernate version: 3.0

Hello,
I'm looking for a Criteria based solution in Hibernate 3 for a query that accesses a many-to-one association where
- either a condition on that association is true
- or the association is null

I succeeded in creating two separate criteria objects, one for each case:
Code:
List list1 =
  session.createCriteria(Foo.class)
         .setProjection(Projections.property("column"))
         .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
         .createCriteria("association")
         .add(Restrictions.eq("val", new Integer(myVal)))
         .list();

List list2 =
  session.createCriteria(Foo.class)
         .setProjection(Projections.property("column"))
         .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
         .add(Restrictions.isNull("association"))
         .list();


My desired result is in this case the union of these two lists.

However, I'm clueless how to construct these conditions in *one* criteria. This becomes necessary when I want to apply my condition on more than one association.

Can anybody direct my in the right direction?
Thanks in advance,
Oliver


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.