-->
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.  [ 5 posts ] 
Author Message
 Post subject: formula with parameter?
PostPosted: Wed Jul 13, 2005 4:43 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
I have a complex query that checks permissions and returns a flag based on which user is asking for the object.

I am trying to populate the flag using a formula. I would like to provide the userId as a parameter to the formula when I query for the object. Is it possible to provide a parameter to the formula?

Hibernate version: 3


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 6:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, but perhaps you should consider the Hibernate3 Filters stuff.


Top
 Profile  
 
 Post subject: nothing works so far.
PostPosted: Thu Jul 14, 2005 2:30 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 6:46 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I am using something like following to get the count of rows from a child table.


Criteria criteria = session.createCriteria(ItemObject.class)
.createAlias("permissions", "perm")
.add( Restrictions.like("permissions.userid","A98B2E93-FA95-4DA8-97FA-030684E1017B"));
ProjectionList properties = Projections.projectionList();
properties.add(Projections.property("id"));
properties.add(Projections.alias(Projections.count("perm.userid"),aliasName));
properties.add(Projections.groupProperty("id"));


Top
 Profile  
 
 Post subject: Re: formula with parameter?
PostPosted: Thu Apr 14, 2011 7:15 am 
Newbie

Joined: Tue Jul 20, 2004 3:47 am
Posts: 4
Hi all

is it in the current hibernate version possible to provide a parameter to the formula?

Use case as described in the example of nHibernate http://www.codewrecks.com/blog/index.ph ... d-filters/


Best regards
Tobi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.