-->
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: Do I misunderstand filters?
PostPosted: Sat Jun 02, 2007 12:46 pm 
Newbie

Joined: Wed Oct 26, 2005 11:55 pm
Posts: 14
Hibernate version: 3.1.3
Name and version of the database you are using: MySQL 5.0

I've had a filter defined for one of my entities for quite a while and thought it was working perfectly. It turns out it is only being applied when I run a query against that entity [eg, Criteria.list()]; it is not applied if I load an entity instance directly via Session.get(). This surprises me and causes me quite a problem (for reasons that I can go into if need be).
Am I misunderstanding how filters are intended to work? And if so, is it documented somewhere? (I've read and re-read chapter 17 of the reference manual)

All my Hibernate code goes through a helper that automatically calls Session.enableFilter(), and here's the relevant part of my mapping XML:

Code:
<hibernate-mapping ...>
    <class name="Document" ...>
        ...
        <property name="isPrivate" type="boolean" not-null="true" />
        ...

        <filter name="nonPrivateDocuments" />
    </class>

    <filter-def name="nonPrivateDocuments" condition="not isPrivate" />
</hibernate-mapping>


TIA,
Eric


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 02, 2007 2:54 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Although I am not answering your question strictly.

If your filter is always enabled.
Instead you could try with a where in the class mapping.
Code:
<class name="Document" where="not isPrivate" ...>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 03, 2007 7:29 pm 
Newbie

Joined: Wed Oct 26, 2005 11:55 pm
Posts: 14
Hmm, that won't work directly because I need to allow some users access to "private" documents. However, I could define a different mapping, NonPrivateDocuments, that uses this technique, and then choose the appropriate mapping based on user role.
Thanks for the idea, but I'd still like to get a response about my understanding of Filters.

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:41 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
From Java persistence with Hibernate book:
12.3.1 Dynamic data filters
Quote:
Retrieval by identifier can’t be restricted with a dynamic data filter. It’s also conceptually wrong: If you know the identifier of an Item, why shouldn’t you be allowed to see it?
...
Similar reasoning applies to filtering of many-to-one or one-to-one associations.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:43 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Then, you could try implementing Hibernate Event Listeners along with the Filters.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 2:08 pm 
Newbie

Joined: Wed Oct 26, 2005 11:55 pm
Posts: 14
pepelnm wrote:
From Java persistence with Hibernate book:
12.3.1 Dynamic data filters
Quote:
Retrieval by identifier can’t be restricted with a dynamic data filter. It’s also conceptually wrong: If you know the identifier of an Item, why shouldn’t you be allowed to see it?
...
Similar reasoning applies to filtering of many-to-one or one-to-one associations.


Thanks, at least that explains that this is an intended design decision (even if I happen to disagree with it).
I've commented on http://opensource.atlassian.com/project ... se/HHH-663 that the documentation really needs to be clarified. It should not be necessary to read the book to understand that limitation, but the current reference manual makes no mention whatsoever about this.

Eric


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.