-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Filters
PostPosted: Thu May 12, 2005 6:33 pm 
Newbie

Joined: Thu May 12, 2005 3:51 pm
Posts: 7
My question is this : Are Hibernate filters applied and translated or are they only appended after the HQL has already been translated into sql?

I would like to use Hibernate filters as a way to enforce some security parameters by being a member of a group on certain objects. I would like to have a many to many relationship on each of the secured objects and create a filter that will limit the objects that are returned by forcing the objects to be in a certain group.

I created a filter that is a list of groups like this:
Code:
<filter-def name="SecurityFilter">
    <filter-param name="OwnerGroupID" type="java.util.ArrayList"/>
</filter-def>


I then created a many to many relationship on a test object and setup the filter:
Code:
<set name="owningGroups" table="OBJECT_GROUP_JOIN" cascade="all" lazy="true" >
  <key column="OBJECT_ID"/>
  <many-to-many column="GROUP_ID" class="com.entity.Group"/>
</set>


<filter name="SecurityFilter" condition="owningGroups.id in (:OwnerGroupID)"/>

In the same file I have a named query that I would like to use:
Code:
<query name="com.entity.SecureObject.findAllInGroup">
  select distinct so from SecureObject so
</query>


I then enable the filter with a set of group objects :
Code:
       
Group groupone = new Group( "one" );
Group grouptwo = new Group( "two" );

List<Group> groupIDs = new ArrayList<Group>();
groupIDs.add(groupOne);
groupIDs.add(groupTwo);
session.enableFilter("SecurityFilter").setParameter("OwnerGroupID", groupIDs);
       
// Find all the groups using the filter
List<SecureObject> list = this.getSession().getNamedQuery(fullQueryName("findAll")).list();


I was hoping that Hibernate would translate the so.owningGroups.id in into a join to the groups table to get the correct owned objects. I believe that Hibernate is simply appending the filter string to the query and not translating the filter into it's correct sql. The sql that is generated is :

Code:
select secureobje0_.ID as ID, secureobje0_.NAME as NAME0_ from domain.SECURE_OBJECT secureobje0_ where owningGroups.id in (?, ?)


If I change the named query to be :
Code:
select distinct so from SecureObject so where so.owningGroups.id in ( :groups )

Hibernate does exactly what I would like it to do.

Is there something that I am not doing correctly?

Thanks

Ryan

Hibernate version:
3.0.1

Name and version of the database you are using:
Oracle 8.1.7


Top
 Profile  
 
 Post subject: Additional Information
PostPosted: Fri May 13, 2005 12:53 pm 
Newbie

Joined: Thu May 12, 2005 3:51 pm
Posts: 7
One other thing that I tried was instead of using named queries, I tried creating a query inline with SQL and using the filter. This produced the same error as described earlier. If I create the query with the filter disabled and the correct oql to do the filtering it works great.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 14, 2005 8:03 pm 
Beginner
Beginner

Joined: Sat Jan 22, 2005 9:11 am
Posts: 35
Location: London
Your suspicions are correct - Hibernate filter conditions are SQL not HQL.

I imagine this will be improved in future releases...


Top
 Profile  
 
 Post subject: Is this still true?
PostPosted: Fri Jul 28, 2006 10:58 am 
Newbie

Joined: Thu May 12, 2005 3:51 pm
Posts: 7
Is it still true that hibernate filters are still not HQL in the latest version of Hibernate?


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