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.