-->
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.  [ 6 posts ] 
Author Message
 Post subject: using a filter with binary parameter
PostPosted: Tue Jan 30, 2007 5:40 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hi,

I'm trying to use Filters (NHibernate version: 1.2.0 beta 3) for implementing a row-bases access control using a bitmask represented as a binary column in the database:

Filter Definition:
Code:
<filter-def name="OwnedObject">
  <filter-param name="ClientMask" type="binary"/>
</filter-def>

Filter usage:
Code:
<filter name="OwnedObject" condition="IsOwner(owner,:ClientMask) = 1)"/>

IsOwner is a stored function which does a bitwise comparision of the masks. When I enable the filter on the session with:
Code:
h.Session.EnableFilter( "OwnedObject" ).SetParameter( "ClientMask", ActiveMask );

I get a ADOException "Could not execute query". I tracked down the problem and found the origin of the problem in NHibernate.Engine.QueryParameter.ProcessFilter(...) line 406:
Code:
if (value != null && typeof(ICollection).IsAssignableFrom(value.GetType())) { ...

I've looked up the same piece of code in Hibernate 3.0 (QueryParameter.java, line 388):
Code:
if ( value != null && Collection.class.isAssignableFrom( value.getClass() ) ) {

Problem is that in .Net arrays implement ICollection and the condition evaluates to true unlike in java, where the condition is false. So the original sql statement
Code:
select partnerhea0_.uid as x0_0_ from sx.bus_partnerheader partnerhea0_ where SX.IsOwner(partnerhea0_.owner,:OwnedObject.ClientMask) = 1 and ((partnerhea0_.uid=?))

results in:
Code:
select partnerhea0_.uid as x0_0_ from sx.bus_partnerheader partnerhea0_ where SX.IsOwner(partnerhea0_.owner,?, ?, ?, ?, ?, ?, ?, ?) = 1 and ((partnerhea0_.uid=?))

which causes the ADOException. In my opinion this is a bug. Does anybody encountered the same problem or is using Filters in a similar approach ?

Any comments will be appreciated,

Thx in advance,
Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 6:10 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This looks like a bug, please open a JIRA issue and attach a test case.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 7:55 am 
Beginner
Beginner

Joined: Mon Jan 08, 2007 11:59 pm
Posts: 31
This does look like a bug. However I was able to get this working by changing the

Code:
if (value != null && typeof(ICollection).IsAssignableFrom(value.GetType()))

to

Code:
if (value != null && type.IsCollectionType)


The reason I did this was because the NH types already have a IsCollectionType property so I checked it instead of depending on the IsAssignableFrom call

Is this a reasonable fix?

Job Samuel.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 8:06 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
No, this is not a valid fix. From the code it looks like the intent was to allow this:
Code:
<filter-param name="AllowedValues" type="int" />
...
<filter ... condition="SomeProperty in (:AllowedValues)" />

i.e. specify the type as an int, but pass a collection of ints instead, since it's not possible to specify the type of "collection of ints" in XML. I guess I would just fix it by making a special case for binary at this time.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 10:02 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I've opened a JIRA issue:

http://jira.nhibernate.org/browse/NH-882


Regards,
Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 6:36 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Thx for the quick fix, works great now :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.