• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate - empty collections don't work with Criterias

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to select Users that belong to Public groups or don't belong to any groups at all. user<->group is a many to many assiociation. (user have a collection of groups associated or empty if doesn't belong to any). I have to use detachedCriterias, so I do as follows:

DetachedCriteria crit = DetachedCriteria.forClass(User.class, "usr");
crit.createAlias("groups", "usrgroups");

Disjunction dis1 = Restrictions.disjunction();
dis1.add(Property.forName("usr.groups").isEmpty());
dis1.add(Property.forName("usrgroups.isPublic").eq(new Boolean(true)));

crit.add(dis1);

...
but this doesn't work, since creating alias on collection 'groups' eliminates users which have no groups (calling isEmpty() gives zero results). How to overcome that?


regards,
Chris
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since you are using detached criterias i think it is H3 you are using.

this is a common problem (see bug tracking for hibernate) but "not a bug". I don't know if the patch has been included in the latests releases (which version are you using ?) but you can take a look at: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1137

if the patch is not applied to H3 and you do not want to / can not apply the patch then you have to use HQL.

pascal
 
I'm doing laundry! Look how clean this tiny ad is:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic