Hi I am using the Grails filter plugin
I am trying to define a default filter as below
// Defined inside the Book entity
static hibernateFilters = {
activeFilter(condition:'active=1', default:true)
}
When i run my integration tests the filter does not apply for dynamic finder methods like
Book.findAll()
If I add the below line in the BootStrap.groovy class
Book.enableHibernateFilter('activeFilter')
Then the filter is applied.
However when the application is run the filter is never applied, with or without the above code in BootStrap.groovy
Any ideas ?
After a little digging around this is what i have found
The hibernate filter plugin works well without the zkgrails plugin however the two cannot seem to work together :(
The below code snippet seems to be the problem for me.
I think we could have two issues here
1) Initially the execution gets to
all(controller:'', action:'')
only once during application startup. I am thinking it should get there each time there is a new request and hence a new session.
2) Even if it somehow gets there after certain modification, I do not think it'll get past all(controller:'', action:'')
composers are used in zkoss
class HibernateFilterFilters {
def filters = {
all(controller:'*', action:'*') {
before = {
def session = grailsApplication.mainContext.sessionFactory.currentSession
DefaultHibernateFiltersHolder.defaultFilters.each {name ->
session.enableFilter(name)
}
}
after = {
}
afterView = {
}
}
}
}
In my Grails 2.5.X app I enable the hibernate filters in a web filter, i.e. I have this code in
grails-app/conf/Filters.groovy
In the integration tests in the plugin itself, the filters are enabled in the setup method of the test class.
After a little digging around I have come up with a workaround for the above problem
I basically extend the GrailsOpenSessionInViewFilter class
}
I also have a entry in the web.xml
Now each time a new session is created the default filters are enabled for it. I think this should work, however it'll be better if some change can be made in the zkgrails plugin or the hibernate filters plugin so that the two can co-exist in a single application :)
Thanks