-->
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: Conjunction / Disjunction and Empty Collections
PostPosted: Thu Mar 13, 2008 3:23 pm 
Newbie

Joined: Tue Apr 12, 2005 4:13 pm
Posts: 3
Hibernate version: 3.2.5

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

I have several tables. The first contains a set of data objects (Resources). Then, there are two permission tables. One to map user permissions to the resource objects and the other to map group permissions to the objects. Previously, I was issuing two queries, one for users, one for groups, and then putting both collections into a set to eliminate redundant objects. Instead I'd like to issue one query, for obvious reasons, but I'm having trouble.

My Criteria Object
Code:
Criteria c2 = session.createCriteria(Resource.class)
   .createAlias("groupPerms", "gps")
   .createAlias("userPerms", "ups")
   .add( Restrictions.isNull("archivedDate"))
   .add( Restrictions.disjunction()
      .add(Restrictions.conjunction()
         .add(Restrictions.isNotEmpty("groupPerms"))
         .add(Restrictions.in("gps.group.id", groupIds))
         .add(Restrictions.ge("gps.permission", new Integer(0)))
      )
      .add(Restrictions.conjunction()
         .add(Restrictions.isNotEmpty("userPerms"))
         .add(Restrictions.eq("ups.user.id", userId))
         .add(Restrictions.ge("ups.permission", new Integer(0)))
      )
   );


Now, the Criteria works great as long as BOTH the GroupPermissions collection AND UserPermissions Collection (of the ResourceObject) are not empty. As soon as one collection is empty for a given resource, that Resource will be ignored even when the other collection matches the criteria.

I even added the check for an empty collection in the criteria and it didn't help. I'm not sure if I'm just missing something obvious, but any help would be appreciated.


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.