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