Reputation: 126
I have created a filter to apply for session of a particular bean. I enable the filter each time the session is fetched:
@Override
protected final Session getHibernateSession() {
enableFilter("filterName",
"parameterName", "parameterValue");
return super.getHibernateSession();
}
Now I want that for a particular query, this filter need not be enabled. There exists an option to disable the filter, but I am not able to find the right place to do so. I tried:
DetachedCriteria criteria = criteria();
// some restrictions and projections
disableFilter("filterName")
return find(criteria);
The problem is, when the find(criteria) is fired, the hibernate session is fetched again, which enables the filter.
Upvotes: 3
Views: 4054
Reputation: 573
I think you have created separate methods for enabling and disabling filters.
You will have to disable the filters in find(criteria) method itself. Instead of doing :
getHibernateSession().createQuery(somequery);
You will have to do something like this :
Session session = getHibernateSession();
session.disableFilter("filterName");
session.createQuery(somequery);
This should work. I also found a link which can help: https://www.tikalk.com/posts/2013/01/28/how-to-activate-and-deactivate-hibernate-filters/
Upvotes: 2