So, here is the problem...
I would like to get the count of all permissions on an object for a given user to determine if it is updatable or not by that user. The count is to be retrieved when the object is, not with a separate query. Also, the whole thing should work with .scroll() , not just .list(), because these are very large data sets that cause out-of-memory exceptions when using .list()
Here's what I tried.
1. Formula...but it doesn't really work because the userid parameter cannot be passed in to it.
2. for the Permission, I defined a many-to-one association to the ItemObject. From the ItemObject defined the inverse one-to-many association. Then did...
List results = session.createQuery("select i from ItemObject i inner join fetch i.permissions as p where p.userid=:userid").setParameter("userid", "A98B2E93-FA95-4DA8-97FA-030684E1017B").list();
Problem is .list() works, .scroll() doesn't, because permision is a set. Though I expect it to return only one item for this query, it is a one-to-many, hence defined as a set.
3. Tried using Criteria with projections to get the ItemObject and count of Permissions.
Criteria criteria = session.createCriteria(ItemObject.class)
.createAlias("permissions", "perm")
.add( Restrictions.like("permissions.userid","A98B2E93-FA95-4DA8-97FA-030684E1017B"))
.setProjection(Projections.projectionList().add(Projections.rowCount()));
...and oops...I would like to set the row count projection on the permissions, not on the ItemObject
4. From what I have seen of filters, it is a nicer, more consistent way of doing what I was trying with (2), but since it did not work with (2), I can't see it workign with filters.
I am out of options. Hope the experts here can suggest an approach.
|